gpt4 book ai didi

python:在连续循环中使用键盘输入?

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:07 25 4
gpt4 key购买 nike

<分区>

操作系统是 Redhat-c​​lone Linux 发行版,我使用的是 python-2.x。

一般的代码结构是:

# stuff is initialized
while True:
# read stuff from remote devices
# process data
# maybe do stuff, or maybe just watch
os.system("clear")
# display status of remote devices
time.sleep(1)

我想让用户通过按各种键来驱动程序。例如。 “按 S 优雅地关闭远程设备,K 杀死,R 重启”。所有这些 Action 都需要在大循环内发生——我的伪代码中的“可能做某事,或者可能只是观看”评论。如果没有按下任何键,程序将继续循环。

我不确定如何在 while True: time.sleep(1) 循环的上下文中完成键盘读取。

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