Python之路【第一篇】:Python基础(5)

python 3.2.3及以下版本没有自带tab补全,python 3.5.1自带tab补全模块。

 
#!/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
 
#for Linux
 
 
import sys
import readline
import rlcompleter
 
if sys.platform == 'darwin' and sys.version_info[0] == 2:
    readline.parse_and_bind("bind ^I rl_complete")
else:
    readline.parse_and_bind("tab: complete")  # linux and python3 on mac
 
#for mac
 
 
>>> import sys
>>> print(sys.path)
['', '/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模块只能在当前目录下导入,如果想在系统的何何一个地方都使用, 要把这个tab.py放到python全局环境变量目录里,一般都放在Python/2.7/site-packages 目录下,这个目录在不同的OS里放的位置不一样,用 print(sys.path) 可以查看python环境变量列表。
 
'',这是代表当前路径,先找当前路径
 
 
posted @ 2016-05-14 02:44  漫画  阅读(601)  评论(0编辑  收藏  举报