我正在尝试从标准输入执行单个字符的非阻塞读取.我找到了curses库的解决方案,但是在尝试将输出写回stdout时我做错了.
import curses
from time import sleep
def callback(screen):
screen.nodelay(1)
return screen.getkey()
while 1:
try:
key = curses.wrapper(callback)
print "Got keypress: ", key
except:
sleep(3)
print "No Keypress"
print "Program\nOutput"
# Prints
No Keypress
Program
Output
Run Code Online (Sandbox Code Playgroud)
除缩进输出外,一切都完美无瑕.有没有什么办法解决这一问题?