【问题标题】:How to set configuration for readline in Python如何在 Python 中为 readline 设置配置
【发布时间】:2018-06-16 12:11:58
【问题描述】:

根据question 的回答,我为python 安装了readline 来解决退格问题。如果我以 root 身份登录 CentOS 7,我可以毫无问题地退格;但是,如果我以用户身份登录,我必须运行 pip install readline 来解决退格问题。我不知道在哪里设置 readline 所以我不需要每次以用户身份登录时都重新安装它。在我的电脑中,它没有定义question 的解决方案之一中提到的“PYTHONSTARTUP”。 任何进一步的帮助和建议将不胜感激。

【问题讨论】:

标签: python readline


【解决方案1】:

注意:我的系统是 CentOS 7。安装了 Intel Python。如果您使用不同的 Python,请查看相应的网站。

在线学习后,我安装了anaconda2,并设置~/.bashrc:

module load anaconda/anaconda2

接下来,设置~/.pystartup(参考link

进口atexit 导入 os,sys 导入 readline 导入 rlcompleter readline.parse_and_bind("tab: complete")

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

def save_history(historyPath=historyPath): 导入读取线 readline.write_history_file(historyPath)

如果 os.path.exists(historyPath): readline.read_history_file(historyPath)

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

另外,我的系统是CentOS 7。集群使用intel编译器和Intel Python。因此,如果您使用的是 Intel Python,请安装anaconda3(5 月 2 日);否则,请参考link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2012-06-07
    相关资源
    最近更新 更多