Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read multiple lines of raw input?

I want to create a Python program which takes in multiple lines of user input. For example:

This is a multilined input. It has multiple sentences. Each sentence is on a newline. 

How can I take in multiple lines of raw input?

like image 460
felix001 Avatar asked Jul 26 '12 07:07

felix001


1 Answers

sentinel = '' # ends when this string is seen for line in iter(input, sentinel):     pass # do things here 

To get every line as a string you can do:

'\n'.join(iter(input, sentinel)) 

Python 2:

'\n'.join(iter(raw_input, sentinel)) 
like image 68
jamylak Avatar answered Sep 26 '22 01:09

jamylak