Skip to main content

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 <https://github.com/welbornprod/colr>`__ module.

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

Output:

printdebug.DebugColrPrinter

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.')

Download files

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

Source Distribution

PrintDebug-0.3.5.tar.gz (27.0 kB view details)

Uploaded Source

File details

Details for the file PrintDebug-0.3.5.tar.gz.

File metadata

  • Download URL: PrintDebug-0.3.5.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for PrintDebug-0.3.5.tar.gz
Algorithm Hash digest
SHA256 4d3b4e64162d611a51161ea08d06ed8c9a10b5697c3a63ccbe6f1baffcde52ab
MD5 0e971f36681022834c481e9899adf917
BLAKE2b-256 c5e92e68cbd0a32e679f3b4ca00e2fe212e6cc994513b6f409eecae0427eb587

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.5 This release

1 file

0.3.0

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.1

1 file

0.1.0

1 file

0.0.5-1

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page