My name is Kazuhiro Minomaki (https://qiita.com/mimaki_kazuhiro) and I am an intern at Future Electronic Technology. This time I will write about ipdb.
Since you are a beginner in programming, the content may be incorrect. If there are any mistakes, I will correct them so please point out more and more.
It provides extensions to pdb, the standard debugger for Python. Debugging is the process of finding and correcting mistakes in a program. Then, install it first.
terminal
$ sudo pip install ipdb
Create a file with an appropriate name.
This time I created a file called test.py
.
test.py
import ipdb
print ("debug program")
a = 10 / 3
b = 10.3 / 3.4
ipdb.set_trace()
print (a,b)
Execute with the following command.
terminal
python3 -m ipdb test.py #file name
Then, on the screen below.
terminal
> /Users/mimakikazuhiro/Desktop/djangosw/test.py(1)<module>()
----> 1 import ipdb
2 print ("debug program")
3 a = 10 / 3
ipdb>
For the time being, press "h" to ask "what kind of function does it have?"
terminal
ipdb> h
Documented commands (type help <topic>):
========================================
EOF cl disable interact next psource rv unt
a clear display j p q s until
alias commands down jump pdef quit source up
args condition enable l pdoc r step w
b cont exit list pfile restart tbreak whatis
break continue h ll pinfo return u where
bt d help longlist pinfo2 retval unalias
c debug ignore n pp run undisplay
Miscellaneous help topics:
==========================
exec pdb
ipdb>
I'll push it in various ways.
terminal
ipdb> n
> /Users/mimakikazuhiro/Desktop/djangosw/test.py(2)<module>()
1 import ipdb
----> 2 print ("debug program")
3 a = 10 / 3
terminal
ipdb> s
debug program
> /Users/mimakikazuhiro/Desktop/djangosw/test.py(3)<module>()
2 print ("debug program")
----> 3 a = 10 / 3
4 b = 10.3 / 3.4
terminal
ipdb> q
End with "q". It seems that you can easily debug like this.
Recommended Posts