import readline

def tab_completer(text, state):
    print('\ntext:', text)
readline.parse_and_bind('tab: complete')
readline.set_completer(tab_completer)
input('Prompt: ')
Python: bind a function to a key