Python: bind function to key

I just started learning python and am writing my own tab completion function for practice / fun (so no one tells me rlcompleter). I am having some problems getting python to call a function. My code is:

import readline def tab_completer(): print readline.get_line_buffer() readline.parse_and_bind("tab: tab_completer") while True: raw_input("Prompt") 

the expected result is that when I press the tab key, it prints what it’s ever typed, no matter what, what actually happens, any tips?

+8
python readline tab-completion
source share
1 answer

Try the following:

 import readline def tab_completer(text, state): print "\ntext:", text readline.parse_and_bind("tab: complete") readline.set_completer(tab_completer) raw_input('Prompt: ') 

Question Completing a tab in raw_input () in Python (which was my link) may also help.

+2
source share

All Articles