[PYTHON] Easy debugging with ipdb

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.

What is ipdb

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

Let's actually operate

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

Easy debugging with ipdb
Debugging C / C ++ with gdb
Debugging pipelines with metaflow
Easy TopView with OpenCV
Easy tox environment with Jenkins
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Debugging with pdb in Python
Useful when debugging with TouchDesigner
Easy folder synchronization with Python
Easy to make with syntax
Easy image classification with TensorFlow
Easy web scraping with Scrapy
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
Easy proxy login with django-hijack
Remote debugging with Visual Studio 2017
[Ipdb] Web development beginners tried to summarize debugging with Python
[Python] Easy parallel processing with Joblib
Easy Slackbot with Docker and Errbot
Easy Jupyter environment construction with Cloud9
Easy GUI app with Tkinter Text
Easy to install pyspark with conda
Easy Python + OpenCV programming with Canopy
Easy email sending with haste python3
Bayesian optimization very easy with Python
Easy AWS S3 testing with MinIO
Easy Japanese font setting with matplotlib
Easy data visualization with Python seaborn.
Easy with Slack using Bot #NowPlaying
Easy to draw graphs with matplotlib
Easy parallel execution with python subprocess
Easy modeling with Blender and Python
Easy animation with matplotlib (mp4, gif)
Easy deployment environment with gaffer + fabric
Easy keyword extraction with TermExtract for Python
[Python] Super easy test with assert statement
[Python] Easy argument type check with dataclass
Easy JSON formatting with standard Linux functions
Easy filter management with Python's -m option
Make GUI apps super easy with tkinter
[Easy] AI automatic recognition with a webcam!
Easy introduction of speech recognition with Python
Easy C / C ++ multilingual binding with CMake + SWIG
[Easy Python] Reading Excel files with openpyxl
Easy web app with Python + Flask + Heroku
Easy image processing in Python with Pillow
[Easy Python] Reading Excel files with pandas
Easy! Use gensim and word2vec with MAMP.
Easy web scraping with Python and Ruby
[Python] Easy Reinforcement Learning (DQN) with Keras-RL
Easy REST API with API Gateway / Lambda / DynamoDB