hell
When you've got to debug your code.
Installing
pip install hell
Requirements
hell supports python 3.4+ and 2.7
Usage
In hell there is a collection of functions with short uppercase names. Most of them print colorized formatted output. Most of them accept short keyword arguments as options.
Colors
- red
- green (default)
- blue
- cyan
- magenta
- yellow
- white
- grey
The first letters are shortcuts for colors:
r
, g
, b
, c
, m
, y
, w
. grey has no shortcut.
Attributes
- bold
- concealed
- dark
- reverse
- underline
- blink
The first letters can be used as well:
b
, c
, d
, r
, u
. blink has no shortcut.
Configuration
There is Config
class to adjust hell. Options are:
option | default | description |
---|---|---|
C_DEFAULT_COLOR | 'green' | Default color of C() output |
F_TEMPLATE | '--> {filename} line {lineno} {funcname}()' | Format string used in F() |
OUT | sys.stdout | Writable file-like object to redirect output to. |
Example configuration change:
import hell
hell.Config.OUT = open('/tmp/debug.out', 'a')
Tools
C(*args, sep=' ', end='\n', c='C_DEFAULT_COLOR', b=None, a=None)
Print args, colorized and formatted according to kwargs.
kwarg | description | default |
---|---|---|
c | color | 'C_DEFAULT_COLOR' |
b | background color | |
a | attributes, str like 'bold' or 'b u' or list of strings like ['bold', 'underline'] | |
sep | separator, same as in built-in print | |
end | end, same as in built-in print |
Examples:
from hell import C
C('Some', 'variables')
C('debug note', c='yellow', b='white', a='underline')
C('shortcuts', c='y', b='w', a='u') # yellow underlined on white
C('multiple attributes', a=['bold', 'underline'])
C('multiple attributes as space-delimited string', a='bold underline')
C('multiple attributes as space-delimited string with shortcuts', a='b u')
C(123, 456, sep='|', end='.')
F(frame=None, c=None, b=None, a=None)
"Where am I?"
Print info about stack frame.
If frame is not provided, frame called F() will be used.
Info includes:
- python filename
- line number
- name of function that called F.
- name of type if function is its method or classmethod
Info is being formatted using Config.F_TEMPLATE
c, b, a are optional termcolor related arguments. See C() for details.
Example usage:
class Class:
def function(self):
F()
Will print:
/path/to/module.py line 105 Class.function()
I(banner='', ipython=True, call_f=True,c=None, b=None, a=None)
Emulate interactive Python console.
Current locals and globals will be available.
banner will be printed before first interaction.
banner=None is for printing default console banner.
See built-in code.InteractiveConsole.interact.
ipython=True indicates using IPython console if available.
When call_f is true, F() will be called printing info where I() was called.
c, b, a are optional termcolor related arguments. See C() for details.
L(sized, c=None, b=None, a=None)
Print the length of sized, colorized and formatted according to keyword arguments.
c, b, a are optional termcolor related arguments. See C() for details.
L('abc', c='b', a='underline')
Returns length with "pipe":
>>> 'abc' | L
3
M(obj, c=None, b=None, a=None)
Print the base classes of type of the obj, or of the obj itself when it is a type.
Bases will be in Method Resolution Order, separated with sep, colorized and formatted according to keyword arguments.
c, b, a are optional termcolor related arguments. See C() for details.
T(obj, c=None, b=None, a=None)
Print the type of obj, colorized and formatted according to keyword arguments.
c, b, a are optional termcolor related arguments. See C() for details.
T(0, c='r', a='bold')
Returns type with "pipe":
>>> 123 | T
<class 'int'>
P(*args, sep=' ', end='\n')
Shortcut for built-in function print writing to Config.OUT
PP(obj, indent=4, width=80, depth=None, compact=False, c=None, b=None, a=None)
Pretty-print colorized python object.
kwarg | description | default |
---|---|---|
indent | amount of indentation added for each recursive level | 4 |
width | desired output width | 80 |
depth | number of levels which may be printed | not limited |
compact (python3) |
format as many items as will fit within the width on each output line |
False |
c | text color, see function C | None |
b | background color, see function C | None |
a | attributes, see function C | None |
from hell import PP
numbers = list(range(10))
PP(numbers, indent=4, width=15, compact=True)
will print
[ 0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11]