如何在 Python 中设置 readline 的配置 [英] How to set configuration for readline in Python

查看:62
本文介绍了如何在 Python 中设置 readline 的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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

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

模块加载anaconda/anaconda2

下一步,设置~/.pystartup(参考link)<块引用>

导入 atexit导入操作系统,系统导入 readline 导入 rlcompleterreadline.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 编译器和 英特尔 Python.因此,如果您使用的是 Intel Python,请安装 anaconda3(5 月 2 日);否则,请参考链接.

According to the answer to question, I installed readline for python to resolve backspace issue. If I logged in CentOS 7 as a root, I can backspace without any problems;however, if I logged in as a user, I have to run pip install readline to resolve backspace problem. I do not know where to set the readline so I do not need to reinstall it every time when I log in as a user. In my computer, it does not define "PYTHONSTARTUP" which is mentioned in one of solutions in question. Any further help and suggestion would be highly appreciated.

解决方案

NOTE: My system is CentOS 7. Intel Python was installed. If you use different Python, please see corresponding websites.

After studying online, I installed anaconda2, and set ~/.bashrc:

module load anaconda/anaconda2

next, set ~/.pystartup (refer link)

import atexit import os,sys import readline import rlcompleter readline.parse_and_bind("tab: complete")

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)

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

In addition, my system is CentOS 7. The cluster is using intel compiler and Intel Python. Thus, if you are using Intel Python, please install anaconda3(may 2);else, please refer link.

这篇关于如何在 Python 中设置 readline 的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆