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.

kyle k
  • 5,134
  • 10
  • 31
  • 45

1 Answers1

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
Crowman
  • 25,242
  • 5
  • 48
  • 56
  • You can also add input_list.pop() before the break if you don't want to include the final blank line in your input. – Crowman Jun 10 '13 at 02:53
  • @kylek Click the tick under his vote count on the left :). However, I think you have to wait a certain amount of minutes – TerryA Jun 10 '13 at 02:58
  • 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. – Crowman Jun 10 '13 at 02:59
  • Thanks for telling me about that feature also. – kyle k Jun 10 '13 at 03:01