Skip to main content

旨在帮助调试体验的轻量级模块

项目描述

调试打印

皮皮 执照 版本 最后一次提交

旨在帮助调试体验的轻量级模块

安装

pip install debugp

用法

用于dp()显示表达式值并保持评估。

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()支持同时打印多个表达式,并以元组形式返回结果

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])

您可以dp()在一行中使用多次

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

配置

风格

您可以使用更改默认颜色dp_conf

from debugprint import *

dp_conf.pseudo = "yellow"

a = 2
dp(dp(1 + 2 * 3) >> dp(a))

前:

前

后:

后

启用/禁用

您可以通过操作启用或禁用调试打印dp_conf.enabled

from debugprint import *

a = 1
dp_conf.enabled = False
dp(dp(1 + 2 * 3) >> dp(a))  # Won't print a thing!

打印挂钩

您可以使用自定义函数将对象转换为字符串!

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

您可以在debugprint/config.py

已知错误

  1. 不能dp()在python交互控制台中使用
  2. dp()当一行中有多个语句时不起作用,即dp(1); dp(2)
  3. 三层嵌套dp()在不同的行中产生意想不到的上下文提示
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

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

debugp-0.1.6.tar.gz (9.2 kB 查看哈希

已上传 source

内置分布

debugp-0.1.6-py3-none-any.whl (9.6 kB 查看哈希

已上传 py3