收录日期:2019/02/17 00:14:49 时间:2010-06-16 01:38:12 标签:python,input,loops,timer

I'd like to have something similar to the following pseudo code:

while input is not None and timer < 5:
    input = getChar()
    timer = time.time() - start

if timer >= 5:
    print "took too long"
else:
    print input

Anyway to do this without threading? I would like an input method that returns whatever has been entered since the last time it was called, or None (null) if nothing was entered.

On *nix you want select with sys.stdin. On Windows you want msvcrt.kbhit() and msvcrt.getch().