Skip to main content

A Python debugger for learner which print out all changes.

Project description

pdbg.py

Table of Contents

Introduction

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

Installation

You can install pdbg with pip

pip install pdbg-bcit

Usage

Using this tool is very simple. In Windows, open CMD in the folder that you would normally run your python script. Then, enter the below command, with $filepath as the absolute path of the python script you want to debug.

python -c "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.

Example

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 command line and run this command, with $filepath as the path of the python file.

python -c "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

Options

pdbg.pdbg(file, func_filter=[], var_filter=[], output_file=None, seperator=", ",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
    • {var_name} will be the name of the variable,
    • {pre-value} will be the initial variable
    • {new_value} will be the variable after changes.
  • Read the Python doc for more about formatting.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdbg-bcit-1.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pdbg_bcit-1.0.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pdbg-bcit-1.0.2.tar.gz.

File metadata

  • Download URL: pdbg-bcit-1.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pdbg-bcit-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e187f4fdadf016ad4d365554faef5721f809c4deeabeee0fa4793efcd5358dc6
MD5 af80b6b0bc7c870e433f40afa516a6d1
BLAKE2b-256 5067362e11155b682f0654c6f649d1a7fca56ea36364988bb67d6b65fc0afb1e

See more details on using hashes here.

File details

Details for the file pdbg_bcit-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pdbg_bcit-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pdbg_bcit-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c885103dbfa3025b104615391b0b50aa457d4f0ecbc90d8426fd2fca9b29de8
MD5 cc8e434f2bf448a80293add0ff23f1e5
BLAKE2b-256 a3b9fb48b6d0658f0b99a319cab4b5cebffb3b020ddc6b929c1b2d5d4ca8a3e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page