Skip to main content

When you've got to debug your code.

Project description

hell

When you've got to debug your code.

Installing

pip install hell

Requirements

Usage

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

  • black
  • grey (Actually black but kept for backwards compatibility)
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • light_grey
  • dark_grey
  • light_red
  • light_green
  • light_yellow
  • light_blue
  • light_magenta
  • light_cyan
  • white

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

Functions

C

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 Config.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

F(frame=None, c=None, b=None, a=None, depth=1)

"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

depth is to control number of stack frames to inspect. E.g. depth=2 is to print info on the function calling F and its caller.

c, b, a are optional termcolor related arguments. See C for details.

Example usage:

class Class:
    def function(self):
        F() # E.g. this lineno is 114

Will print:

/path/to/module.py line 114 Class.function()

I

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

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

M(obj, c=None, b=None, a=None, sep=' | ')

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.

P

P(*args, sep=' ', end='\n')

Shortcut for built-in function print writing to Config.OUT

PP

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]

T

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

Contributing

Read here

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

hell-0.4.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hell-0.4.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file hell-0.4.2.tar.gz.

File metadata

  • Download URL: hell-0.4.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hell-0.4.2.tar.gz
Algorithm Hash digest
SHA256 9ef5d8a08939bd0ac65000c7ff4b0bdca6708ae57b16e10575cd23d1fa15466a
MD5 1ac6125f907a9f3bc572797839dbf829
BLAKE2b-256 281cbcd4a66e6894dfb69ad2078eb7a2da1be8542e304d9e614b8ff93edc6e85

See more details on using hashes here.

File details

Details for the file hell-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: hell-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hell-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 36172b252adaf1f846a03669b3ca3d5cba17c6864f90962308c53a036dad33e5
MD5 043825511ece156c9a681e490c75a603
BLAKE2b-256 771b62bfb6861e09eced565a7c0910d01f72fd0b7ad63d1a8b4765abc6b41a50

See more details on using hashes here.

Supported by

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