while count != 5:
input_text = input("Please insert a number of lines of text \n")
if count != 5:
print("Count is " + str(count))
对于上面的代码,当提示提供输入时,如果我粘贴带有多个换行符的文本。代码将运行换行符的数量!我只想让它对整个文本运行一次。
有人可以帮忙吗?
最佳答案
您可以使用sys.stdin.read()
,但它需要您手动发送EOT字符:
>>> import sys
>>> x = sys.stdin.read()
the quick brown fox
jumped over the lazy
dog
>>> print(x)
the quick brown fox
jumped over the lazy
dog
>>>
注意,粘贴后最后我使用 Enter,然后使用 ctrl-D。
关于Python 3 : How to ignore line breaks when using input(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42871100/