raw_input on several lines

Raja Baz entropy88 at gmail.com
Sun Aug 3 02:42:46 EDT 2008


On Sat, 02 Aug 2008 21:58:09 +0200, TP wrote:

> Hi everybody,
> 
> When using raw_input(), the input of the user ends when he types Return
> on his keyboard.
> How can I change this behavior, so that another action is needed to stop
> the input? For example, CTRL-G. It would allow the user to input several
> lines.
> 
> Thanks
> 
> Julien

Well I don't know about using CTRL-G. Now I'm pretty sure you can't 
change the behavior of raw_input() like this *but* what you do is the 
following:

>>> from sys import stdin
>>> user_input = stdin.readlines()
this
is 
a multiline
test
>>> user_input
['this\n', 'is\n', 'a multiline\n', 'test\n']
>>> 

The end of the input is marked by the "End of Transmission" or "End of 
File" character(which can be obtained via ctrl+D, at least on linux, I 
have no idea about win32)
This would have the additional bonus of working with something being 
piped into it as an input



More information about the Python-list mailing list