用户登录
用户注册

分享至

python交互模式下实现tab自动补全功能

  • 作者: Tel_1878886----
  • 来源: 51数据库
  • 2022-09-21
建立.pythonstartup文件
$ cat .pythonstartup

# cat ~/.pythonstartup

# python startup file

#!/usr/bin/env python
import sys
import readline
import rlcompleter
import atexit
import os

# tab completion
readline.parse_and_bind('tab: complete')
# history file
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
定义变量到~/.bash_profile
$ echo 'export PYTHONSTARTUP=~/.pythonstartup' >> ~/.bash_profile
最后重新登陆shell,输入python命令进入交互模式,就可以用Tab键进行补全

软件
前端设计
程序设计
Java相关