raw_input on several lines

Larry Bates larry.bates at websafe.com`
Sat Aug 2 16:22:53 EDT 2008


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
> 
> 
Just put raw_input() in a loop and check for something.  Actually a blank line 
would probably work best in that case.  Not tested, but you will get the idea:

lines = list()
print 'Enter your text (empty line to quit)'
while 1:
     line = raw_input('')
     if line.strip() == '':
         break

     lines.append(line)



-Larry



More information about the Python-list mailing list