Skip to content
A small debug printing module for Python. Recursively prints lists, tuples, and dicts. Can print a debug message that includes the file name, function name, and line number.
Python
Branch: dev
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
printdebug
test
.gitignore
CHANGES.txt
DESC.txt
LICENSE.txt
MANIFEST
MANIFEST.in
README.md
setup.py

README.md

PrintDebug

A small debug printing module that prints extra info like filenames, function names, and line numbers. It can also recursively print objects such as lists, tuples, and dicts.

More useful stuff may be added in the future.

Example Usage:

Debug printing:

from printdebug import debug
def myfunction():
    debug('Hello from myfunction.')

myfunction()

Output:

   myfile.py:    3                 myfunction(): Hello from myfunction.

Formatting:

The default format for line information is '{filename}:{lineno:>5} {name:>25}(): ', but can be set with the fmt arg:

debug('Test', fmt='#{lineno} in function {name}, file: {filename}')

The format can be set once, and used every time with a DebugPrinter instance, or by overriding printdebug.default_format:

from printdebug import DebugPrinter

dp = DebugPrinter(fmt='{filename}: {name}():#{lineno}')
dp.debug('Test')

There is a default colorized format, using the colr module.

from printdebug import DebugColrPrinter
dp = DebugColrPrinter()
dp.debug('Test')

Output:

printdebug.DebugColrPrinter

Print an object:

from printdebug import printobject

o = {'key1': {'subkey1': 'value1', 'subkey2': 'value2'}}
printobject(o)

Output:

key1:
    subkey1:
        value1
    subkey2:
        value2

Silencing debug prints:

debug() and DebugPrinter() can be silenced with debug_enable(False):

from printdebug import debug, debug_enable

debug('This will print.')

debug_enable(False)
debug('This will not.')

debug_enable()
debug('This will print now.')
You can’t perform that action at this time.