From 5fc145cc9fa7d753c1c2c6c523ea2fb87235ba38 Mon Sep 17 00:00:00 2001 From: rydesun Date: Fri, 27 Jan 2023 21:51:42 +0800 Subject: [PATCH] Update python startup: add python-rich --- .config/python/repl_startup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.config/python/repl_startup.py b/.config/python/repl_startup.py index 5a3918d..55f77a0 100644 --- a/.config/python/repl_startup.py +++ b/.config/python/repl_startup.py @@ -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