Giter VIP home page Giter VIP logo

pdbg.py's Introduction

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 absolute 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
    • Absolute 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
  • seperator
    • Seperator 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.

pdbg.py's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.