[Tutor] User Input with Multiple Lines

eryksun eryksun at gmail.com
Mon Oct 27 01:18:41 CET 2014


On Sun, Oct 26, 2014 at 3:25 PM, Malik Brahimi <mbrahimi02 at gmail.com> wrote:
> So I am working with input that is pasted from a PDF file, and I was
> wondering if there is any way I can do so without the program terminating
> abruptly because of the newlines.

input() and raw_input() grab a single line of text. The rest of the
lines, if any, remain in the input buffer. As you know, you can loop
to build a list and then '\n'.join() the list. To instead grab the
whole buffer, you can use sys.stdin.read(). In this case you need to
manually write EOF to the buffer at the start of a new line. In a
POSIX terminal that's Ctrl-D. In the Windows console use
Ctrl-Z+Return. You may already be familiar with these as a shortcut
for exiting the shell.


More information about the Tutor mailing list