python - 如何读取多条原始输入?

标签 python input user-input

我想创建一个接受多行用户输入的 Python 程序。例如:

This is a multilined input.
It has multiple sentences.
Each sentence is on a newline.

如何接收多行原始输入?

最佳答案

sentinel = '' # ends when this string is seen
for line in iter(input, sentinel):
    pass # do things here

将每一行作为字符串,您可以做:

'\n'.join(iter(input, sentinel))

Python 2:

'\n'.join(iter(raw_input, sentinel))

关于python - 如何读取多条原始输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11664443/

相关文章:

python - 使用 Python 从 epub 中提取文本

Python - 注释 True 值(并使用其他值)

C++模板输入验证

html - 如何在屏幕上打印用户输入的数据

windows - 终端中是/否问题的标准格式?

python - python 按照用户定义的次数执行函数

python - 根据条件切割列表尾部

python - 在 python 中显示像素数组中的图像时出错

javascript - 如何将输入值匹配到数组的整个范围?

javascript - 如何直接显示input的值