3

I would like to know how to write a simple program that can accept multiple lines of input, then the input can be submitted like in the lynx browser, where you use a blank line and then a period to submit the input.

i want to use it in an email program.

3
  • Possible duplicate of stackoverflow.com/questions/11664443/… Commented Jun 10, 2013 at 2:47
  • This question is a little different, i am asking how to submit the input. Commented Jun 10, 2013 at 2:49
  • Ah, so you already know how to get the multiline input? Commented Jun 10, 2013 at 2:50

1 Answer 1

10

Here's a simple way:

#!/usr/bin/python

input_list = []

while True:
    input_str = raw_input(">")
    if input_str == "." and input_list[-1] == "":
        break
    else:
        input_list.append(input_str)

for line in input_list:
    print line
Sign up to request clarification or add additional context in comments.

4 Comments

You can also add input_list.pop() before the break if you don't want to include the final blank line in your input.
@kylek Click the tick under his vote count on the left :). However, I think you have to wait a certain amount of minutes
There should be a checkmark symbol to the left of my answer, when you ask a question, you're supposed to click that for the answer which best answers your question.
Thanks for telling me about that feature also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.