1. 程式人生 > >給python2.6的交互模式加一個TAB補全

給python2.6的交互模式加一個TAB補全

python

首先新建一個tab.py文件
duwens-MacBook-Air:~ duwen$ cd /Library/Python/2.7/site-packages/
duwens-MacBook-Air:site-packages duwen$ sudo touch tab.py
Password:
duwens-MacBook-Air:site-packages duwen$ vim tab.py 
duwens-MacBook-Air:site-packages duwen$ sudo vim tab.py 

內容是:

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")

設置好環境變量,並編譯

duwens-MacBook-Air:~ duwen$ vim ~/.bash_profile 
duwens-MacBook-Air:~ duwen$ source ~/.bash_profile

添加的內容是

export PYTHONSTARTUP=/Library/Python/2.7/site-packages/tab.py

給python2.6的交互模式加一個TAB補全