345353 发表于 2016-7-8 10:00:46

Python终端下添加tab健补全功能

#需求

为了方便工作,我们需要在Python终端下添加Tab健补全功能

#存放脚本路径
Pyhton2.6

1
/usr/lib/python2.6/site-packages/




Python2.7

1
/usr/lib/python2.7/dist-packages/






#脚本代码
1
2
3
4
5
6
7
8
# cat /usr/lib/python2.6/site-packages/tab.py
try:
    import readline
except ImportError:
    print("Module readline not available.")
else:
    import rlcompleter
    readline.parse_and_bind("tab: complete")





#bashrc文件配置

1
2
# tail -1 /etc/bashrc
export PYTHONSTARTUP="/usr/lib/python2.6/site-packages/tab.py"





#注销重新登陆

1
# login





#测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.
sys.__class__(            sys.argv                  sys.maxint
sys.__delattr__(            sys.builtin_module_names    sys.maxsize
sys.__dict__                sys.byteorder               sys.maxunicode
sys.__displayhook__(      sys.call_tracing(         sys.meta_path
sys.__doc__               sys.callstats(            sys.modules
sys.__excepthook__(         sys.copyright               sys.path
sys.__format__(             sys.displayhook(            sys.path_hooks
sys.__getattribute__(       sys.dont_write_bytecode   sys.path_importer_cache
sys.__hash__(               sys.exc_clear(            sys.platform
sys.__init__(               sys.exc_info(               sys.prefix
sys.__name__                sys.exc_type                sys.ps1
sys.__new__(                sys.excepthook(             sys.ps2
sys.__package__             sys.exec_prefix             sys.py3kwarning
sys.__reduce__(             sys.executable            sys.setcheckinterval(
sys.__reduce_ex__(          sys.exit(                   sys.setdlopenflags(
sys.__repr__(               sys.flags                   sys.setprofile(
sys.__setattr__(            sys.float_info            sys.setrecursionlimit(
sys.__sizeof__(             sys.getcheckinterval(       sys.settrace(
sys.__stderr__            sys.getdefaultencoding(   sys.stderr
sys.__stdin__               sys.getdlopenflags(         sys.stdin
sys.__stdout__            sys.getfilesystemencoding(sys.stdout
sys.__str__(                sys.getprofile(             sys.subversion
sys.__subclasshook__(       sys.getrecursionlimit(      sys.version
sys._clear_type_cache(      sys.getrefcount(            sys.version_info
sys._current_frames(      sys.getsizeof(            sys.warnoptions
sys._getframe(            sys.gettrace(               
sys.api_version             sys.hexversion            
>>> sys.





页: [1]
查看完整版本: Python终端下添加tab健补全功能