为了在 Terminal 中使用 Python 更加方便,在 home 目录下添加脚本 .pythonstartup,内容如下,

然后在 .bashrc 中添加 export PYTHONSTARTUP=~/.pythonstartup

这样就能在 Terminal 中使用 Tab 实现 Python 的自动补全了。

 

#!/usr/bin/python
#
#-----------------------------------------------------------------------------
#
# Usage: 
#   - rename this file to ".pythonstartup"
#   - put it under your home directory, e.g. "~"
#   - modify .bashrc, add following line,
#       export PYTHONSTARTUP=~/.pythonstartup
#
#-----------------------------------------------------------------------------

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

 

完。

 

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2021-12-10
  • 2021-12-05
  • 2021-12-23
  • 2021-07-27
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-11-25
相关资源
相似解决方案