티스토리 뷰


update

 Visual Studio Code 에서 python debugger 이용하기

위의 글에서 이야기 하는 Visual Studio Code 의 plugin 이 제일 나은 듯 하다.


--------------------------------------------


파이썬 프로그램을 작성할 때 사용할 debugger 를 소개 해 볼까 한다.

 

GUI debugger

보통 가장 많이 쓰고 가장 편하고 직관적인 것은 역시 GUI debugger 같다. 굳이 사용법은 설명을 하지 않아도 간단하다.

GUI debugger 는 일반적인 python IDE 에서 찾아볼 수 있다.

python IDE가 여러가지 존재하겠지만, 내가 사용해 본 녀석은 아래 두 녀석이다.

  • pyScripter
  • pyDev(Eclipse plug-in)

개인적으로 pyScripter 가 빨라서 좋다. Eclipse 는 조금 느린듯한 느낌을 지울 수 없다.

 

 

Command Line Debugger

 

pdb(http://docs.python.org/library/pdb.html)

command line debugger 이다. gdb 같은 command line debugger 를 좋아한다면 아래와 같은 방법으로 debugging 을 할 수 있다.


만약 muChart.py 라는 파일을 debugging 한다고 한다면

c:\> python –m pdb muChart.py

라고 입력하면 된다.

c:\>python -m pdb muChart.py

d:\mine\programming\eclipse\python\mucharts\src>c:\Python27\python.exe -m pdb mu
Chart.py
> d:\mine\programming\eclipse\python\mucharts\src\muchart.py(4)<module>()
-> import httplib2
(Pdb) help

Documented commands (type help <topic>):
========================================

EOF    bt         cont      enable  jump  pp       run      unt
a      c          continue  exit    l     q        s        until
alias  cl         d         h       list  quit     step     up
args   clear      debug     help    n     r        tbreak   w
b      commands   disable   ignore  next  restart  u        whatis
break  condition  down      j       p     return   unalias  where

Miscellaneous help topics:
==========================
exec pdb

Undocumented commands:
======================
retval rv

 

 

c resume 같은 기능, 멈춰있는 program을 다시 run 하게 한다.
b break point 를 설정한다.
n 다음 line 으로 넘어간다.
visual c++에서 f10 과 같은 용도이다.
s(Step in) 함수안으로 들어간다.
f11 과 같은 역할이다.
p <변수이름> 변수를 보여준다.
pp <변수이름> pretty-print 로 변수를 보여준다.
l 현재 위치 근처의 source code 를 보여준다.

 

pdb breakpoint 잡는 방법

아래 3가지가 가능하다.

  • (Pdb) break muChart.py:110
    line 110 에서 멈춘다.(참고로 muChart.py 에서 실행 중이라면, muChart.py 는 생략할 수 있다.)
  • (Pdb) break muChart.py.main()
    main() 함수가 호출될 때 멈춘다.
  • (Pdb) break muChart.py:110, variable_name > 100
    variable_name 이라는 변수의 값이 100 이상일 때만 line 110에서 멈춘다.


PyCharm


JetBrains 에서 만든 Python IDE 이다. Community version (free) 을 제공한다.
개인적으로 가장 마음에 드는 IDE 이다. source navigation 이 편하다.
속도도 eclipse 보다 빠르다.



See Also

  1. The Best Python IDEs You Can Use for Development


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함