pdbg is a debugging tool for python. It is designed to be a simple and lightweight tool for troubleshooting errors in Python code.
When run, this tool will run the specified script, while outputting all the variable definitions during the run. This is useful for when you want to watch the changes made to variables during the execution of your code and you don't have an IDE with a debugger. This is also useful even when you do have a debugger, as many debuggers don't allow you to go back to previous steps in your code, making it easy to forget what the previous values were. This tool will show you all the changes at once in the command line output or in a file, meaning that forgetting what happened will never be an issue.
All of the functionality of this module is provided through a single function. The options for this function are detailed in the Options section of this document
You can install pdbg
with pip
pip install pdbg-bcit
Using this tool is very simple. Open your terminal and start python. Then, enter the below script, with $filepath
as the relative path of the python script you want to debug.
import pdbg
pdbg.pdbg(r"$filepath")
This method will run the script and output all the variable definitions and changes in the targeted file. More options for this method are detailed in options.
Lets say we have a file with the following code.
def foo():
bar = 0
for i in range(3):
bar += 1
print(bar)
foo()
If we wanted to watch the variables changed in foo()
, all we would have to do is open python and run this script, with $filepath
as the path of the python file.
import pdbg
pdbg.pdbg(r"$filepath", "foo")
And this would be our output:
[Function] Entering function foo
[Debug] bar = 0 bar { None => 0 }
[Debug] for i in range(3): i { None => 0 }
[Debug] bar += 1 bar { 0 => 1 }
[Debug] for i in range(3): i { 0 => 1 }
[Debug] bar += 1 bar { 1 => 2 }
[Debug] for i in range(3): i { 1 => 2 }
[Debug] bar += 1 bar { 2 => 3 }
3
pdbg
.pdbg(file, func_filter=[], var_filter=[], output_file=None, separator=", ",output_format="{var_name} {{ {pre_value} => {new_value} }}")
-
[Required]
file
- Path to your Python script.
-
func_filter
- Filter the output by function name.
-
var_filter
- Filter the output by variables name.
-
output_file
- Defaults to None. Redirect the output of pdbg to a file if specified. Will output by printing in console otherwise
-
separator
- Separator used when multiple variables are changed in one line.
-
output_format
-
A string that formats the output
-
Placeholders:
{var_name}
: The name of the variable,{pre-value}
: The initial variable{new_value}
: The variable after changes. -
Read the Python doc for more about formatting.
-
-