打开当前主目录
cd ~
新建文件 vim .pythonstartup
<pre name="code" class="python">import rlcompleter
import readline
import atexit
import os
# http://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion
if 'libedit' in readline.__doc__:
readline.parse_and_bind('bind ^I rl_complete')
else:
readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'], '.pyhist')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del readline, rlcompleter, histfile, os
保存退出
加入环境变量:
echo 'export PYTHONSTARTUP=~/.pythonstartup' >> ~/.bash_profile重启shell即可。
本文介绍如何配置Python环境以实现交互式会话的自动补全功能及历史命令保存。通过简单的脚本设置,可以在Shell中获得更高效的Python命令输入体验。
1437

被折叠的 条评论
为什么被折叠?



