Update python startup: add python-rich

This commit is contained in:
rydesun 2023-01-27 21:51:42 +08:00
parent 73de4c5983
commit 5fc145cc9f

View file

@ -1,7 +1,9 @@
import atexit
import os
import readline
from functools import partial
# 命令历史的记录文件
xdg_data_home = os.getenv(
'XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
data_dir = os.path.join(xdg_data_home, 'python')
@ -15,5 +17,14 @@ except FileNotFoundError:
readline.read_history_file(readline_history_file)
readline.set_history_length(1000000)
atexit.register(readline.write_history_file, readline_history_file)
# 让输出的数据结构和Traceback带有语法高亮
# 需要安装python-rich
try:
from rich import inspect, pretty, traceback
pretty.install()
inspect_methods = partial(inspect, methods=True)
traceback.install()
except Exception:
pass