try:
    return matches[state]
except IndexError:
    return None
readline.set_completer(completer)
readline.parse_and_bind('tab: menu-complete')
while 1:
    a = input('> ')
print('said:', a)
Howto do python command-line autocompletion but NOT only at the beginning of a string