Python 3 : How to ignore line breaks when using input()

标签 python python-3.x input file-io line-breaks

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/

相关文章:

python - 从 'Keys' 导入 'selenium.webdriver.common.keys'

python - 多个 RDD 的 Spark union

python - 如何从文件中打印特定行

python - 在 Python 中从命令行输入变量

java - 扫描仪仅读取第一行

php - 允许用户编辑 php 代码并安全地提交结果

python - 将字典传递给构造函数?

python - wxCollapsiblePane 强制框架调整大小

Pythonic 整数乘法和加法

python - 在分隔符处加入 python 列表