相关疑难解决方法(0)

如果使用颜色提示,请查看如何在Python readline中修复列计算

我使用标准技巧来定制交互式Python会话:

$ cat ~/.bashrc
export PYTHONSTARTUP=~/.pystartup

$ cat ~/.pystartup
import os
import sys
import atexit
import readline
import rlcompleter

historyPath = os.path.expanduser("~/.pyhistory")

def save_history(historyPath=historyPath):
    import readline
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

term_with_colors = ['xterm', 'xterm-color', 'xterm-256color', 'linux', 'screen', 'screen-256color', 'screen-bce']
if os.environ.get('TERM') in term_with_colors:
    green='\033[32m'
    red='\033[31m'
    reset='\033[0m'
    sys.ps1 = red + '>>> ' + reset
    sys.ps2 = green + '... ' + reset
del term_with_colors

atexit.register(save_history)
del os, sys, atexit, readline, rlcompleter, save_history, historyPath

现在我得到上下文敏感的完成和颜色提示.

问题来自颜色提示 - 当我在交互式Python会话中调用历史搜索 - 向后搜索 …

python terminal interpreter readline

19
推荐指数
2
解决办法
2283
查看次数

标签 统计

interpreter ×1

python ×1

readline ×1

terminal ×1