如果经常在linux的命令行下面调试python程序,对于用惯了Pycharm的人来说,是非常的痛苦啊,没有tab补全,还要自己一个一个的敲,多么痛的领悟,现在好了,有了这个脚本,命令行模式下也能tab补全了,走起!
1 vi /root/.pythonstartup
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import readline
import rlcompleter
import atexit
import os
readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file,histfile)
del os, histfile, readline, rlcompleter
2 执行下面的命令
echo "export PYTHONSTARTUP=~/.pythonstartup" >> ~/.bashrc
source /root/.bashrc
搞定!
注意: 要在root用户下执行,如果是普通用户,需要将 “/root/.pythonstartup” 更换为 “/home/your_name/.pythonstartup”