最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python 3.4.3等待用户输入超时自动跳过
时间:2016-02-29 编辑:简简单单 来源:一聚教程网
import sys,time,msvcrt
def readInput(caption, default, timeout=10):
start_time = time.time()
sys.stdout.write('%s(%d秒自动跳过):' % (caption,timeout))
sys.stdout.flush()
input = ''
while True:
ini=msvcrt.kbhit()
try:
if ini:
chr = msvcrt.getche()
if ord(chr) == 13: # enter_key
break
elif ord(chr) >= 32:
input += chr.decode()
except Exception as e:
pass
if len(input) == 0 and time.time() - start_time > timeout:
break
print ('') # needed to move to next line
if len(input) > 0:
return input+''
else:
return default
#使用方法
iscaiji=readInput('请输入你的名字','aaa')
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24