Multiline user input python

2020-02-01 12:29发布

问题:

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.

回答1:

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


标签: python input