Skip to main content

Print tools for debuging

Project description

Introduction

Quick Debug functions to print informations on the context.

Each function has 3 optional keyword-only arguments :

  • i : indent level (defaults to 0)

  • indent_str : indent string for one level (defaults to 2 spaces)

  • stream : file-like object to output (defaults to stderr)

These two last parameters are actually defaulted to the module variables dbug._Dindent_str and dbug._Dstream.

Each functions F exist in 2 flavours :

  • F : normal

  • nF : print a new line before

Functions available

  • [n]D(*args, **kw) : Simply prints *args

  • [n]Dvar(*expr, **kw) : Print for each expression expr : f'{expr} = {eval(expr)}\n'

  • [n]DWAI(**kw) : Print W-here A-m I with this format : module.function(param=val_param, param2=val_param2...) # /path/to/function/definition:line_of_DWAI_call

  • [n]DNL(**kw) : Print a N-ew L-ine (i and indeit_str have no effect on this one

  • Dnop(res, *args) : Returns res, so that one can execute any side effect function in a list comprehension (best used with Dvar())

  • DnopL(*args, res) : Same as Dnop but execute the side effects first

Classes Available

There is also the Dbug class which takes as parameters stream and indent_str and have the normal version of the previous functions without the leading D, passing them stream and defaulting the indent level to Dbug.indent_level

  • Dbug.__call__(*args, **kw) calls D

  • Dbug.var(*expr, **kw) calls Dvar

  • Dbug.var(*expr, **kw) calls Dvar

  • Dbug.WAI(**kw) calls DWAI

  • Dbug.NL(**kw) calls NL

This class is also a context manager and you can do things like

with Dbug(open('log', 'w')) as D :
  D.WAI()
  D.var('a')

As a shortcut to change the indent level for a Dbug instance object, you can use the shift operator

with Dbug(open('log', 'w')) as D :
  D.WAI()
  D>>1  # indent level is now 1
  D.var('a')
  D<<1  # indent level is back to 0

Installation

pip install dbug

HISTORY

1.0.b5

  • FIX Intempestive print in D()

  • FIX Readme orthograph

1.0.b4

  • ADD __all__ module variable to export only relevent objects

  • ADD Dbug Class

  • FIX Typo on D() which prevented using the passed stream

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

dbug-1.2.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file dbug-1.2.tar.gz.

File metadata

  • Download URL: dbug-1.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.3

File hashes

Hashes for dbug-1.2.tar.gz
Algorithm Hash digest
SHA256 c9790c9631aa746b441d80691e2a377db31c00704ccff12feb1d9713e6a92936
MD5 f442cdf7166562ff82954d68eb9db49f
BLAKE2b-256 d30126b4952e183f734dd72c9780c9119e1f6e0827bfa0b02a50b2d56cfe4b72

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