How can I handle the char immediately after its input, without waiting an endline?

Steven D'Aprano steve at
Sat Oct 25 11:04:01 CEST 2008

On Sat, 25 Oct 2008 08:36:32 +0000, Lie Ryan wrote:

>>>> I want to write something that handle every char immediately after
>>>> its input. Then tehe user don't need to type [RETURN] each time. How
>>>> can I do this?
>>>> Thanks in advance.
> Don't you think that getting a one-character from console is something
> that many people do very often? 


I can't think of any modern apps that use one character commands like 
that. One character plus a modifier (ctrl or alt generally) perhaps, but 
even there, it's mostly used in GUI applications.

> Do you think that all these platform
> independent code should be moved to the interpreter level instead 

Absolutely not! There's no need for it to be given a keyword or special 

But maybe there should be a standard library function for it. 

> (and
> raises the appropriate error when the platform somehow cannot do
> unbuffered input)? So python developer could do something like this:
> raw_input(bufferring = 0)

No. Leave raw_input as it is. A better interface would be:

import input_services
c = input_services.get_char()

Eventually the module could grow other services as well.


More information about the Python-list mailing list