我試圖從標準輸入讀取單個字符的非阻塞讀取。我已經找到了curses庫的解決方案,但是在嘗試將輸出寫回標準輸出時,我做錯了什麼。從標準輸入讀取單個字符的Python curses影響打印語句的輸出
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
除縮排輸出外,一切都完美無缺。有沒有什麼辦法解決這一問題?
謝謝。打印'\ r \ n'完美無缺! –