gpt4 book ai didi

python - 杀死Python中的输入

转载 作者:行者123 更新时间:2023-12-03 13:03:46 24 4
gpt4 key购买 nike

有没有一种方法可以简单地从另一个线程杀死input()
例如,如果一段时间过去了,而用户仍然没有在input()中输入任何内容,是否有办法简单地“杀死” input()

最佳答案

您无法杀死input()
但是,您可以使用sys.stdin iterable,for循环和标志(或某些函数)执行几乎相同的操作。

import sys

stopReadingInput = False
for line in sys.stdin :
# Insert some code that involves user input
if stopReadingInput : # Here you can call a function to check if you don't need user input anymore, instead of if statement. Otherwise you'll have to change the flag value from outside.
break

关于python - 杀死Python中的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41912543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com