pythonic生物人

一行代码,让Python error更清晰,让bug无处遁形!

分享一个python error美化工具:pretty_errors。

pretty_errors是一个优秀的Python库,能够提供更友好、易读的error追踪信息。通过美化栈跟踪,它使开发者更容易定位和理解代码中的问题。

pretty_errors支持自定义样式,能够适应不同的团队和个人偏好。这个库提供了更加人性化的error信息展示,有助于提高开发效率和代码调试的便捷性。


pretty_errors安装

python -m pip install pretty_errors

pretty_errors使用

一个简单的例子,

  • 使用pretty_errors前
print "hello world"
Image

File "/Users/xx/Desktop/studying/py/1.py", line 1

  print "hello world"

  ^^^^^^^^^^^^^^^^^^^

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

File "/Users/xx/Desktop/studying/py/1.py", line 1

  print "hello world"

  ^^^^^^^^^^^^^^^^^^^

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

  • 使用pretty_errors后

通过python -m pretty_errors开启pretty_errors,Image

复杂的例子,Image

  • 个性化pretty_errors显示

有四个方法可用,

pretty_errors.configure()

pretty_errors.whitelist()

pretty_errors.blacklist()

pretty_errors.pathed_config()

  • 关闭pretty_errors

通过python -m pretty_errors,输入c,关闭pretty_errors,Image

Option: [default: 0] c

Attempting to remove the following files:

/Users/xx/.local/lib/python3.11/site-packages/usercustomize.py... OK

ref:https://github.com/onelivesleft/PrettyErrors


-END-

Image

我的学习小圈子👉
加入

赞、在看就是最大的支持Image