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

Lie Ryan lie.1296 at gmail.com
Sat Oct 25 13:57:19 EDT 2008


On Sat, 25 Oct 2008 09:04:01 +0000, Steven D'Aprano wrote:

> 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?
> 
> No.
> 
> 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
> syntax.

By "interpreter level", I meant python's VM including its standard 
libraries (i.e. anywhere but at end-programmer's level), I don't mean it 
should have a keyword or special syntax or anything of that sort.

> 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()

That would be fine as well.

> 
> Eventually the module could grow other services as well.
> 






More information about the Python-list mailing list