windows,放在python的lib庫目錄下編輯tab.pypython
#!/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
macwindows
#!/usr/bin/env python # encoding: utf-8 import readline,rlcompleter #[size=16]# Indenting #[/size] class TabCompleter(rlcompleter.Completer): """Completer that supports indenting""" def complete(self, text, state): if not text: return (' ', None)[state] else: return rlcompleter.Completer.complete(self, text, state) readline.set_completer(TabCompleter().complete) #[size=16]# Add autocompletion #[/size] if 'libedit' in readline.__doc__: readline.parse_and_bind("bind -e") readline.parse_and_bind("bind '\t' rl_complete") else: readline.parse_and_bind("tab: complete") #[size=16]# Add history #[/size] import os histfile = os.path.join(os.environ["HOME"], ".pyhist") try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) del histfile
使用import tabcode