[Tutor] Getting multi-line input from user

wormwood_3 wormwood_3 at yahoo.com
Wed Jan 7 04:31:59 CET 2009


>>> For starters you can simplify things a lot:
>>> 
>>> user_input = []
>>> entry = raw_input("Enter text, 'done' on its own line to quit: \n")
>>> while entry != "done":
>>>    user_input.append(entry)
>>>    entry = raw_input("")
>>> user_input = ' '.join(user_input)
>>> print user_input
>>> 
>>> 2) How can I combine and print the output so that paragraphs and the like are preserved?
>>> 
>>> I don't understand. Please give an example.


That is much cleaner, thanks!

On point 2, say I enter:
Enter text, 'done' on its own line to quit: 
I am a sentence. I am another sentence.

I am a new paragraph.
done

What I get out is:
I am a sentence. I am another sentence.  I am a new paragraph.

But that just shows the double new lines of my new paragraph as an extra space. I'd like to print it out so it appears just as it was typed in, with appropriate newlines.

-Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090106/02c51215/attachment.htm>


More information about the Tutor mailing list