python 交互界面tab补全

Posted on 2016-02-16 18:05  心在北方  阅读(433)  评论(0编辑  收藏  举报

创建一个tab.py文件

代码:

#!/usr/bin/env python

import readline
import rlcompleter
import atexit
import os

# tab completion

readline.parse_and_bind('tab:complete')

#history file

historyfile = os.path.join(os.environ['HOME'],'.tab')

try:
    readline.read_history_file(historyfile)
except:
    pass

atexit.register(readline.write_history_file,historyfile)

del os,historyfile,readline,rlcompleter


>>> import sys
>>> sys.path
['', '/usr/lib/python2.7/site-packages/Django-1.8.2-py2.7.egg', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']

将tab.py复制到 /usr/lib64/python2.7/site-packages 下

>>> import tab
>>> os.
就可以补全了

 

Copyright © 2024 心在北方
Powered by .NET 9.0 on Kubernetes