A light weighted module aimed to help debug experience
Project description
debugprint
A light weighted module aimed to help debug experience
Install
pip install debugp
Usage
Use dp()
to show the expression value and keep evaluate.
import numpy as np
from debugprint import dp
dp(
np.dot(
np.array([1, 2, 3]),
np.array([[1], [2], [3]]),
)
)
[21:37:28] Debug info of line 11 in <module>: debugprint.py:50
np.dot(np.array([1, 2, 3]), np.array([[1], [2], [3]])): [14]
dp()
support printing multiple expressions at the same time, and returns the result in a tuple
from debugprint import dp as _dp
def print_arguments(*args):
print(args)
print_arguments(
*_dp(1 + 2 * 3, [x for x in range(10) if x % 3 == 0])
)
[08:34:17] Debug info of line 9 in <module>: debugprint.py:50 debugprint.py:50
1 + 2 * 3: 7
[x for x in range(10) if x % 3 == 0]: [0, 3, 6, 9]
(7, [0, 3, 6, 9])
You can use dp()
multiple times in a line
from debugprint import dp as _dp
a = 2
_dp(_dp(1 + 2 * 3) >> _dp(a))
[08:49:04] Debug info of line 5 in <module>: debugprint.py:27
1 + 2 * 3: 7
a: 2
_dp(1 + 2 * 3) >> _dp(a): 1
Configuration
Style
You can change the default color with dp_conf
from debugprint import *
dp_conf.pseudo = "yellow"
a = 2
dp(dp(1 + 2 * 3) >> dp(a))
Before:
After:
Enable / Disable
You can enable or disable debug print by manipulating dp_conf.enabled
from debugprint import *
a = 1
dp_conf.enabled = False
dp(dp(1 + 2 * 3) >> dp(a)) # Won't print a thing!
Print Hook
You can use a custom function to convert object to string!
from debugprint import *
from objprint import objstr
class A:
def __init__(self, foo, bar):
self.foo = foo
self.bar = bar
self.baz = B()
class B:
def __init__(self):
self.x = 1
self.y = 2
obj = A("foo", "bar")
dp(obj) # information from repr(obj) is not helpful
dp_conf.print_hook = objstr # change the hook from repr to objstr
dp(obj)
[09:50:25] Debug info of line 17 in <module>: debugprint.py:27
obj: <__main__.A object at 0x000001985793E950>
Debug info of line 20 in <module>: debugprint.py:27
obj: <A 0x1985793e950
.bar = 'bar',
.baz = <B 0x1985793e8f0
.x = 1,
.y = 2
>,
.foo = 'foo'
>
You can find more detail in debugprint/config.py
Known Bugs
- Cannot use
dp()
in the python interactive console dp()
does not work when multiple statements in one line, i.e.dp(1); dp(2)
- Three layers of nested
dp()
in different lines produces unexpected context hint
dp(
dp(
(1, (
dp(2)))
) + (2,)
)
[13:45:35] Debug info of line 9 in <module>: debugprint.py:28
2: 2
Debug info of line 7 in <module>: debugprint.py:28
(1, dp(2)): (1, 2)
Debug info of line 6 in <module>: debugprint.py:28
(1, dp(2)): (1, 2, 2) # uh-oh
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
debugp-0.1.6.tar.gz
(9.2 kB
view hashes)
Built Distribution
debugp-0.1.6-py3-none-any.whl
(9.6 kB
view hashes)