这个功能是以 lib 的形式提供的,配置写到 home 下的. pythonrc 文件中, 并设置好环境变量让 python 启动时执行初始化:
- # ~/.pythonrc
- # enable syntax completion
- # add the next line to your ~/.bashrc
- # export PYTHONSTARTUP=~/.pythonrc
- try:
- import readline
- except ImportError:
- print("Module readline not available.")
- else:
- import rlcompleter
- readline.parse_and_bind("tab: complete")
- readline.parse_and_bind('''control-l:" "''')
最后一行是绑定 control 和 "L" 健,自动补四个空格作缩进。因为 tab 键已经被征用了,所以只能用其它组合健作缩进。
来源: