標籤:
首先需要知道python的讀取路徑
>>> 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/lib/python2.6/site-packages‘]
可以看到python可以去這些地方讀取,我們把指令碼放在/usr/lib64/python2.6 即可
[[email protected] python2.6]# cat startup.py
#!/usr/bin/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
這樣做一個問題就是,你每次啟動python後,都需要手動匯入一下,比如
>>> import startup
可以在系統內容變數中,加入讀取路徑,這樣就免去了每次匯入的麻煩
[[email protected] python2.6]# cat ~/.bashrc
export PYTHONSTARTUP=/usr/lib64/python2.6/startup.py
即可
python中的tab補齊