How to make a python, command-line program autocomplete arbitrary things
This entry is based on this SO post.
You have an interactive command-line Python script and you want to add autocompletion to it when hitting the TAB key.
Here is a working example (taken from here):
import readline addrs = ['firstname.lastname@example.org', 'email@example.com', 'firstname.lastname@example.org'] def completer(text, state): options = [x for x in addrs if x.startswith(text)] try: return options[state] except IndexError: return None readline.set_completer(completer) readline.parse_and_bind("tab: complete") while True: inp = raw_input("> ") print "You entered", inp