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")
# 如果没有readline 模块, 需要自己安装一个
$ python
>>> import sys
>>> sys.path
>>> ['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages/setuptools-33.1.1-py2.7.egg']
# 选取一个你有写权限的路径 如
# /Library/Python/2.7/site-packages
# 将tab.p文件拷贝到此路径下
# $ sudo cp tab.py /Library/Python/2.7/site-packages
执行命令行语句, 加入环境变量 PYHTONSTARTUP:
$ echo "export PYTHONSTARTUP=/Library/Python/2.7/site-packages/tab.py" >> /Users/xxx/.bashrc
$ source /User/xxx/.bashrc
搞定 测试
$ python
>>> import os
>>> os.
>>> ...