A utility that cures the horrible traceback displays in Python, making them more readable.
Project description
TBVaccine is a utility that pretty-prints Python tracebacks. It automatically highlights lines you care about and deemphasizes lines you don’t, and colorizes the various elements in a traceback to make it easier to parse.
Here are some screenshots. This is the before:
And this is the after:
If you add the hook or call TBVaccine in your code, it can also print all variables in each stack frame. That is, it turns this:
into this:
Installation
To install, use pip:
pip install tbvaccine
You are done!
Usage as a command-line utility
TBVaccine can be used from the command line several ways.:
python -m tbvaccine myscript.py
Or just pipe STDERR into it from the program you want to watch:
./myscript.py 2>&1 | tbvaccine
And all the tracebacks will now be pretty!
Usage as a Python library
There are various ways to use TBVaccine as a Python library.
Initialize it like so:
from tbvaccine import TBVaccine tbv = TBVaccine( code_dir="/my/code/dir", isolate=True )
code_dir marks the directory we code about. Files under that directory that appear in the traceback will be highlighted. If not passed, the current directory, as returned by os.getcwd() will be used.
If isolate is False, all lines are colorized, and code_dir is ignored.
If show_vars is False, variables will not be printed in each stack frame.
To use it in an except block:
from tbvaccine import TBVaccine try: some_stuff() except: print(TBVaccine().format_exc())
To make it the default way of printing tracebacks, use add_hook() (which also accepts any argument the TBVaccine class does):
import tbvaccine tbvaccine.add_hook(isolate=False) 1 / 0
Bam! Instant pretty tracebacks.
Epilogue
This library is still pretty new, please contribute patches if something doesn’t work as intended, and also please tell your friends about it! Hopefully one day it will be implemented in the Python interpreters themselves.
– Stavros
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
Built Distribution
File details
Details for the file tbvaccine-0.1.3.tar.gz
.
File metadata
- Download URL: tbvaccine-0.1.3.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca7ec780d6c0978f78b69610bb7b94f4e51f28a307e3efe28e2502ff8b3acd84 |
|
MD5 | cdbb39050490ead66d79a48f091f77d7 |
|
BLAKE2b-256 | c4e437e2bdbad4da655f2edccc0a55fe05b423fa1792d889d5ef42122e5a4a25 |
File details
Details for the file tbvaccine-0.1.3-py2-none-any.whl
.
File metadata
- Download URL: tbvaccine-0.1.3-py2-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7cac18a1839ed84bacd6782116a9ff4c9226c8bc3dbacfab62e8976138aecee |
|
MD5 | 2e0dc2479fb99bef32ae84c862b64c02 |
|
BLAKE2b-256 | c919be9bf1462858ebae88c71f7ea2bd31d41d45325eeb4036abfe120d89e9ba |