Python pdb: In the Python program, pdb module is used as a debugger. It comes under the part of standard Python distribution, so it is available all the time. Using this, you can make the setting for breakpoints and single-stepping at the source level. If you don’t have the permissions for accessing the GUI debugger, you can use it.
Furthermore, it has the features like pausing your program, looking at the values of your variables, and watching the program execution step-by-step. The main goal of the Python pde is to provide an interactive debugging environment for developers to debug Python Programs.
In this article, you will learn Cheat Sheet for Python Pdb. Use these commands to save your programming time. Let’s get into this article.
Last Updated on Mar 4, 2022.
Invoking the Debugger Commands:
In the below table, you will learn about invoking the debugging commands and their functions of Python pdb. Please follow these commands carefully.
|import pdb; pdb.set_trace()||Use this command to make invoking the debugger within the code.|
|python -m pdb file.py||This shortcut will invoke from the command line.|
In the below table, you will learn basic commands and their functions of Python pdb. Kindly use these commands wisely.
|p||If you want to print the variable value, you can use this command.|
|pp||Use this command to pretty-print the value.|
|a||By using this command, you can print the input args of the function.|
|locals||This command is used to show the local variables.|
|c||Used to continue the program.|
|r||In order to run the program until the function returns, you can use this command.|
|<Enter>||Make use of this command to repeat the previous command.|
|i||Helps to print the nearby code.|
|l from,to||Use this command to print the code between the lines.|
|w||This command is used to make the i+ trace back|
|u||In order to make the call stack up, you can use this command.|
|d||Make use of this command to down the call stack.|
|q||It is used to quit the program.|
|h||If you want to help and info on this program, you can use this command.|
The below table explains breakpoints commands and their functions of Python pdb. Use these commands carefully.
|b 45||Make use of this command to set on the line for 45.|
|b 45, x == ‘abc’||In order to set the condition, you can use this command.|
|b||With this command, you can list out the current breakpoints.|
|b funcName||Use this command to set the breakpoint in function.|
|b file.py:41||It is used to set on the line of the file.|
|cl||used to clear all the breakpoints.|
|cl 42||To clear breakpoint #42, you can use this command.|
|tbreak …||By using this command, you can hit only once.|
|disable 42||This command is used to turn off breakpoint #42.|
|enable 42||Make use of this command to enable breakpoint #42.|
|ignore 42 [N]||Use this command to ignore the bp#42 N times.|
You can use these commands for both Windows 10 and Windows 11 operating systems. Kindly make sure to use these shortcuts properly to save your working time.
From this article, you will learn Cheat Sheet for Python Pdb. Thank you for reading this article. I hope this article is helpful!. If you have any questions or doubts regarding this article, please share with us in the comment section.