Python Debugging using PDB
Python Debugging
PDB is a library that allows you to extract Python scripts. This article will discuss how to use it in a very simple way.
We can run a Python script from the command line to debug.
1 | python -m pdb t.py |
How to use Python PDB
When executed this way, the script debug process will start from the beginning of the code.
Here, we can start our debug process. Of course, we started the Debug process from the first line with this process. This is not the case. For this reason, we can write the following code on any line in the script.
1 | import pdb; pdb.set_trace() |
We will interpret our program until we write this code, and after that, it will drop us to the Pdb shell. Now we do the simple code that we wrote, and then we run it from the command line normally without using the – pdb.
1 2 3 4 5 6 7 8 | def try(a): print "This is function" print "before pdb" import pdb; pdb.set_trace() print "before call function" try(5) print "after call function" |
the program was interpreted normally until it came to the PDB line and dropped us to the PDB shell after it came to the line. That’s all we need to do to debug. Now, let’s see what we can do after we fall into the PDB shell.
Python Debugging Commands
- l(ist) : Allows us to list the code we have written.
- w(here) : Writes the line where the program is.
- c(ontinue : Allows the program to continue to interpret where it left off.
- b(reak) SatirNumarasi : Break point to the line number.
- tbreak SatirNumarasi : Temporarily puts break point. After the first transaction, break point is deleted.
- q(uit) : Exits debug.
- c(lear) : Used to clean break points. If y(es) answer is given to the question, break points are deleted.
- commands BreakPointNumarasi : Enters the break point number to run the desired commands. Its use is as follows. The end statement is used to exit command.
- s(tep) : Move to the next row.
- n(ext) : Move to the next row.
- j(ump) SatirNumarasi :Jumps to the typed line number.
- a(rgs) :Returns the arguments of the default function.
- p a :a prints the value of the variable to the screen.
- run : Reboot the Debug program.
https://www.kalogroup.com.au/. Самая свежая информация трубный прокат в спб тут.