开发者

Hot python input loop

开发者 https://www.devze.com 2023-01-04 02:42 出处:网络
I\'d like to have something similar to the following pseudo code: while input is not None and timer < 5:

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 n开发者_开发百科othing was entered.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消