我有raw_input命令的问题。我在程序中使用它,并在cmd中运行程序。然后它询问输入,但是当我粘贴其中有空行的文本时,则Python自动将其作为输入命令。我想让它明白它不是输入命令,而是新行。我怎么能这样做?cmd中的raw_input Python
0
A
回答
1
要做到这一点,您不能使用raw_input
函数,因为此函数在第一个新行字符后完成读取输入。相反,你可以使用sys.stdin
:
>>>import sys
>>>input = sys.stdin.read()
hi
this text has
new lines
Ctrl^D
>>>print input
hi
this text has
new lines
读完输入你要发送EOF字符,它在Linux是按Ctrl +d和Windows是按Ctrl +ž
希望这会有所帮助!
0
根据python文档,raw_input()被设计为具有\n
作为结束输入的关键,并且它没有被设计用于另一种交互方式。
如果您想使用另一种使用输入的方式,您可以尝试使用fileinput()
或sys.stdin.read()
,并遍历线条或字符并创建要查找的行为。
看一看的问题的答案,如that one
相关问题
- 1. 中的raw_input Python变量到CMD
- 2. raw_input python
- 3. raw_input Python
- 4. Python raw_input()
- 5. 的raw_input()在Python
- 6. Python中的线程+ raw_input
- 7. 回顾Python中的raw_input/input
- 8. Python中的raw_input函数
- 9. raw_input()中的Python EOF错误
- 10. python隐藏raw_input
- 11. Python:改变raw_input?
- 12. python raw_input()syntax
- 13. Python:扫描raw_input
- 14. Python raw_input(“”)错误
- 15. python中添加raw_input数
- 16. Python EOF错误raw_input()
- 17. Python,输入和raw_input
- 18. python raw_input不工作
- 19. Python:使raw_input执行
- 20. Python 2.7 raw_input脚本
- 21. 的raw_input的Python发行
- 22. Python-没有的raw_input工作
- 23. 特定范围的Python Raw_Input
- 24. 使用raw_input的Python中的EOF错误
- 25. if语句的raw_input和Python中
- 26. 从python中的raw_input打印结果
- 27. python中的raw_input没有按下输入
- 28. Python 2.7 bug中的raw_input输出“None”
- 29. Google App Engine shell中的Python raw_input
- 30. 设置函数调用python中的raw_input
很难明白到底是什么导致你的问题没有看到一些代码。你能否加入一个简短的程序(10行左右)来重现问题? –
第一次搜索给了我:[如何处理原始数据的蟒蛇](http://stackoverflow.com/questions/19202407/how-to-process-raw-data-in-python#answer -19202500) –