[Python] Debugging is more efficient!

Introduction

I often use print () for debugging programs, but it seems that it can be done more efficiently by using pdb, so note

manner

Write the following command at the point you want to debug.

import pdb; pdb.set_trace()

This is OK. If you run the program after inserting this, the process will stop at the insertion part. You can also step in using the following commands.

command table
s (step) Step in
n (next) Step over
r (return) Step out
l (list) View source code for the current line
a (args) Show the arguments of the current function
p Print
c (cont(inue)) Run to the next breakpoint

Postscript

By the way, even if you do not insert it in the program, when you execute the script,

$ python -m pdb <Script name>

But it can be used. (Thanks to @shiracamus.)

Recommended Posts

[Python] Debugging is more efficient!
python DS debugging
Python is easy
Python debugging tips
What is python
Python is instance
What is Python
[Python] What is Pipeline ...
[Python] Super useful debugging
[Python] What is virtualenv
Watershed makes undercoating more efficient
Python round is not strictly round
How Python __dict__ is used
Debugging with pdb in Python
Python is painful. But use
Python is an adult language
Python list is not a list
[Python] Python and security-① What is Python?
Python release cycle is faster!
[Python] * args ** What is kwrgs?
Python | Jupyter> Post-mortem debugging | pdb.post_mortem ()
Identity and equivalence Python is and ==
Full understanding of Python debugging
What is a python map?
Python Basic Course (1 What is Python)
What's new in datetime that is a bit more useful in Python 3
What is Python? What is it used for?
[Python] What is a zip function?
[Python] What is a with statement?
Python Note: About comparison using is
ppa: jonathonf / python-3.6 is now private
Difference between == and is in python
Use fabric as is in python (fabric3)
Golang vs. Python – Is Golang Better Than Python?
Python is UnicodeEncodeError in CodeBox docker
[Python] What is @? (About the decorator)
Which is better, PyPy or Python?
[python] What is the sorted key?
Python for statement ~ What is iterable ~
Efficient net pick-up learned with Python
There is no switch in python
Today's python error: image is blank
What is the python underscore (_) for?
Determining which OS is running Python
Python> What is an extended slice?
Python in is also an operator