Created
January 29, 2011 14:51
-
-
Save christoomey/801888 to your computer and use it in GitHub Desktop.
Python tab completion using readline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import readline | |
readline.parse_and_bind("tab: complete") | |
class VolcabCompleter: | |
def __init__(self,volcab): | |
self.volcab = volcab | |
def complete(self,text,state): | |
results = [x for x in self.volcab if x.startswith(text)] + [None] | |
return results[state] | |
words = ['dog','cat','rabbit','bird','slug','snail'] | |
completer = VolcabCompleter(words) | |
readline.set_completer(completer.complete) | |
line = raw_input('prompt> ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment