simple tab completionUse custom tab-completion in your console programs, like this:
#from http://effbot.org/librarybook/readline.htm
#You do it like this,
class Completer:
def __init__(self, words):
self.words = words
self.prefix = None
def complete(self, prefix, index):
if prefix != self.prefix:
self.matching_words = [w for w in self.words if w.startswith(prefix)]
self.prefix = prefix
try:
return self.matching_words[index]
except IndexError:
return None
import readline
# a set of more or less interesting words
validanswers = [ 'yes', 'no', 'maybe', 'tuesday', 'never' ]
completer = Completer(validanswers)
readline.parse_and_bind("tab: complete")
readline.set_completer(completer.complete)
# try it out!
while True:
answer = raw_input("Answer the Question: ")
if answer not in validanswers:
print "Wrong!"
else:
print "Your answer is",answer • Wrote irmen at 01:00
(edited 1×, last on 15 Nov 2006)
| read 235× | Add comment