如何完成 sys.stdin.readlines() 输入? [英] How to finish sys.stdin.readlines() input?
问题描述
这可能是一个愚蠢的问题,但因为我找不到答案,所以我不得不问.
在交互式 python 中,我想处理我收到的消息:
<预><代码>>>>消息 = sys.stdin.readlines()一切正常,但是...如何阻止它获取输入并将其保存到消息变量中?使用 ctrl+c 停止会停止整个过程,因此不会在任何地方保存输入.我想有一个简单的答案我就是找不到...
对于基于 unix 的系统:
你好,你可以录音:Ctrld
Ctrld 通过发送 EOF.
示例:
<预><代码>>>>导入系统>>>消息 = sys.stdin.readlines()你好世界我的名称是詹姆士键# <ctrl-d>发送的EOF>>>打印信息['Hello ', 'World ', 'My ', 'Name ', 'Is ', 'James ', 'Bond ']对于 Windows:
要在 Windows 上发送 EOF,您可以将 Ctrld 替换为 Ctrlz
This might be a silly question, but as I can't find an answer, I have to ask it.
In interactive python I want to process a message which i get with:
>>> message = sys.stdin.readlines()
Everything works fine, but... how to stop it from getting an input and make it save into message variable? Stopping with ctrl+c stops whole process so there is no input to be saved anywhere. I guess there's an easy answer I just can't find...
For unix based system :
Hello, you can tape : Ctrld
Ctrld closes the standard input (stdin) by sending EOF.
Example :
>>> import sys
>>> message = sys.stdin.readlines()
Hello
World
My
Name
Is
James
Bond
# <ctrl-d> EOF sent
>>> print message
['Hello
', 'World
', 'My
', 'Name
', 'Is
', 'James
', 'Bond
']
For Windows :
To send EOF on Windows, you can replace Ctrld by Ctrlz
这篇关于如何完成 sys.stdin.readlines() 输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!