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:
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.')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file PrintDebug-0.2.1.tar.gz
.
File metadata
- Download URL: PrintDebug-0.2.1.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c5c606e706bffb04ba367af5977ed6c325741087eb9d7a83ed288953de7f51f |
|
MD5 | fd30557e50dc24f3dca6c8c9456a8fd4 |
|
BLAKE2b-256 | fd11660de768b1efc81443da30010be8b83363ace266ec00788c7d4ee20021ae |