该操作系统是一个Redhat-clone 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可重新启动”。所有这些动作都需要发生在大循环中--在我的伪代码中的“可能做些什么,或者可能只是看一下”注释。如果没有按键,程序应该继续循环。
我不确定如何在while True: time.sleep(1)循环的上下文中完成键盘读取。
发布于 2011-06-09 10:24:13
这是一个curses tutorial which starts at a basic level and accelerates quickly。
发布于 2016-07-12 17:54:19
下面的代码对我来说很好。
while True:
choice = raw_input("> ")
choice = choice.lower() #Convert input to "lowercase"
if choice == 'exit':
print("Good bye.")
break
if choice == 'option1':
print("Option 1 selected")
if choice == 'option2':
print("Option 2 selected")https://stackoverflow.com/questions/6286935
复制相似问题