Python rich库,美化控制台打印
- 安装rich库
pip install rich - 使用示例
from rich.pretty import pprint as rich_print app_env = "prod" # 环境标识 dev_env = {"dev", "test"} # 开发/测试环境标识 def mprint(*args, **kwwargs): if app_env in dev_env: rich_print(*args, **kwwargs) else: pass # 美化打印数据结构 data = { "name": "张三", "age": 30, "is_student": False, "courses": ["数学", "物理"], "address": None, } mprint(data)
# rich库的打印会自动添加颜色,并且遇到太长的输出,会自动格式化,可以方便查看调试结果。
浙公网安备 33010602011771号