清除Windows和UNIX上的输入缓冲区:
def flush_input():
try:
import msvcrt
while msvcrt.kbhit():
msvcrt.getch()
except ImportError:
import sys, termios #for linux/unix
termios.tcflush(sys.stdin, termios.TCIOFLUSH)
如果仅需要Windows支持,可使用以下方法:
def flush_input():
while msvcrt.kbhit():
msvcrt.getch()