Python-我需要一种生成多行输入的特定方法
我需要一个脚本来用Python进行多行输入。 这是我计划的一部分:Python-我需要一种生成多行输入的特定方法,python,text,input,line,break,Python,Text,Input,Line,Break,我需要一个脚本来用Python进行多行输入。 这是我计划的一部分: input_ = input("Enter text:\n") #This can handle only single line of text 像这样: Enter text: This is frst line, #Variable input_ would be only this line this is second line, this is last line. 我需要一些东西,将要求用户输入文本(多行文本
input_ = input("Enter text:\n") #This can handle only single line of text
像这样:
Enter text:
This is frst line, #Variable input_ would be only this line
this is second line,
this is last line.
我需要一些东西,将要求用户输入文本(多行文本)
当用户粘贴文本(Ctrl+C)并按Enter键时,程序
需要将全文放入列表中
注意,请不要将此标记为重复,因为它与其他问题有点不同,这对我没有帮助。尝试使用while循环:
listed = []
inputs = None
while inputs != '':
inputs = input()
listed.append(inputs)
listed = [i for i in listed if i != '']
print listed
您如何知道输入何时结束?当用户按Enter键时,输入即结束。在多行输入中,每行后面都会有一个换行符(Enter)。您如何将其与“用户输入结束输入”区分开来?用户需要粘贴文本,一旦按下enter键,输入结束。请参阅下面我的答案。用户可以粘贴,然后按enter键。如果我输入“某个段落\n\n某个段落”?它应该可以正常工作,直到输入为空。但用户需要在输入后按enter键两次,我是否可以解决此问题?否,这是处理多行输入所能达到的最接近的程度。好的,您可以编辑将文本保存到列表中的代码吗(1行=1个列表项)