这是我在运行Debian测试的笔记本电脑上设置的.pythonrc.py
文件的内容:
import os, readline, rlcompleter, atexit
history_file= os.path.join(os.environ['HOME'], '.python_history')
try:
readline.read_history_file(history_file)
except IOError:
pass
readline.parse_and_bind("tab: complete")
readline.parse_and_bind('"\e[A": history-search-backward')
readline.parse_and_bind('"\e[B": history-search-forward')
readline.parse_and_bind('"C-\e[A": reverse-search-history')
readline.parse_and_bind('"C-\e[B": forward-search-history')
readline.set_history_length(8000)
atexit.register(readline.write_history_file, history_file)
del os, readline, rlcompleter, atexit, history_file, __file__
我在运行macOs Sierra的Macbook中有一份相同文件的副本,与.profile
文件相结合,如下所示:
自动完成和历史搜索在Bash上可以正常工作,但是在通过pythonic
别名运行Python时,相同的功能似乎无法正常工作。如果可能的话,有人能解释一下这种行为的原因以及如何解决它吗?在
我建议将keybindings添加到}。在
.inputrc
,任何使用Readline库的应用程序都会使用它。那么您不需要将它们添加到.profile
或{格式不同(稍微简单一点):
(Readline库本身并不关心对历史文件的读写,因此该部分需要保留在pythonrc文件中。)
在MacOS,},这有不同的配置语法。在
readline
moudle使用libedit
而不是{您可以安装
gnureadline
package,或者使用自制程序安装一个使用GNU readline
的新python二进制文件,或者更改rc配置。在正如您指定的
-c 'import user'
,user
模块查找并执行.pythonrc.py
,其功能与PYTHONSTARTUP
相同,因此您只需要一个。在此外,在
~/.profile
中定义的shell变量在bash进程本身中是可行的,但是python作为bash的子进程运行,您必须导出PYTHONSTARTUP
以使其对python可用:相关问题 更多 >
编程相关推荐