首页 > 编程语言 > 详细

Python 在 Terminal 中的自动补全

时间:2017-12-03 12:26:51      阅读:284      评论:0      收藏:0      [点我收藏+]

为了在 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

 

完。

 

Python 在 Terminal 中的自动补全

原文:http://www.cnblogs.com/gaowengang/p/7965508.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!