Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python get raw_input but manually decide when string is done

I want someone to type words in the console, and autocomplete from a list when they hit "tab" key. However, raw_input won't return a string until someone hits [Enter].

How do I read characters into a variable until the user hits [Enter]?

*Note: I don't want to use import readline for autocompletion because of OS issues.

like image 744
atp Avatar asked May 04 '10 09:05

atp


1 Answers

There is an official FAQ entry on this question, for Unix: http://www.python.org/doc/faq/library/#how-do-i-get-a-single-keypress-at-a-time

Edit (copied from Donal Fellows' comment below): "The problem is that the terminal is in “cooked” mode by default (allowing simple line editing) and that to get the keys as they're typed, it has to be placed in “raw” mode." (Thanks!)

like image 90
Eric O Lebigot Avatar answered Oct 18 '22 06:10

Eric O Lebigot