Python Debugger pdb

2 min

language: ja bn en es hi pt ru zh-cn zh-tw

Hello, I'm incompetent.
When you write a fair amount in Python, you sometimes forget how things work, so I want to debug.

In bash, debugging can be done with set -x, but if you want to do something similar in Python:

import pdb
~omitted~
pdb.set_trace() # Where you want to debug

Then, you can execute the next line with n and display stored variables with p variable_name.

After that, just look at the debugging commands and execute them according to your needs.
It's equivalent to gdb in C language.

Debugging is truly important to ensure it's working as intended, I think.

By the way, recently in my head, I keep thinking "Don't use try ~!", but it's easy, so I end up writing it. Then, I thought about rewriting it, but it seems that many Python libraries themselves can only be handled with exception processing, so I shouldn't have the same feeling as with other compiled languages or shell scripts.

Related Posts