Skip to content

Instantly share code, notes, and snippets.

@christoomey
Created January 29, 2011 14:51
Show Gist options
  • Save christoomey/801888 to your computer and use it in GitHub Desktop.
Save christoomey/801888 to your computer and use it in GitHub Desktop.
Python tab completion using readline
#!/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