[Tutor] Getting multi-line input from user
wormwood_3
wormwood_3 at yahoo.com
Wed Jan 7 04:18:12 CET 2009
Hello everyone,
I'd like to prompt the user for input and get back multiple lines, for example if someone wanted to enter a few paragraphs. Then I'd like to be able to print their input out and preserve formatting. Here's what I have so far:
control = True
user_input = []
while control:
if not user_input:
entry = raw_input("Enter text, 'done' on its own line to quit: \n")
user_input.append(entry)
else:
entry = raw_input("")
user_input.append(entry)
if entry == "done":
del user_input[-1]
control = False
user_input = ' '.join(user_input)
print user_input
So you end up with:
Enter text, 'done' on its own line to quit:
I am some text.
And I am more.
I am a new paragraph.
done
I am some text. And I am more. I am a new paragraph.
1) Is there a more elegant/common way to get multi-line user input than this sort of thing?
2) How can I combine and print the output so that paragraphs and the like are preserved?
Thanks,
Sam
_______________________
Samuel Huckins
Homepage - http://samuelhuckins.com
Tech blog - http://dancingpenguinsoflight.com/
Photos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090106/b114a216/attachment.htm>
More information about the Tutor
mailing list