1、使用python命令行查找不熟悉使用方法时,python命令行没有自带tab补全功能问题

[root@docker ~]# vim tab.py
#!/usr/bin/env python 
# python startup file 
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

2、代码有了,但还需将脚本放到python指定的目录下,可以使用sys.path来查看

>>> import sys
>>> sys.path
['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages']

一般会将代码放在/usr/lib64/python2.6/site-packages目录下,可在任何目录下直接导入

>>> sys.
sys.__class__(              sys.__stdout__              sys.executable              sys.path
sys.__delattr__(            sys.__str__(                sys.exit(                   sys.path_hooks
sys.__dict__                sys.__subclasshook__(       sys.exitfunc(               sys.path_importer_cache
sys.__displayhook__(        sys._clear_type_cache(      sys.flags                   sys.platform
sys.__doc__                 sys._current_frames(        sys.float_info              sys.prefix
sys.__excepthook__(         sys._getframe(              sys.getcheckinterval(       sys.ps1
sys.__format__(             sys.api_version             
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐