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 lists, tuples, and dicts.

Project description

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

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

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

PrintDebug-0.3.0.tar.gz (23.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: PrintDebug-0.3.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PrintDebug-0.3.0.tar.gz
Algorithm Hash digest
SHA256 18233a50196bd8f51a6bec3f11519966e2891bb8ba1fcb29644fc8927b609c44
MD5 159126d22d2b9e4cf389cde1d3fe83f6
BLAKE2b-256 bef64e00609a553d77a046f1eba11ae942e41418214f34a64a5ce579e88a731d

See more details on using hashes here.

Supported by

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