python程序运行进程、使用时间、剩余时间显示功能的实现代码
有很多程序运行时间比较长,如果不将运行过程输出将很难判断程序运行的时间。下边这段程序将按照上图所示的格式输出程序运行进程、已用时间、剩余时间。
deftime_change(time_init):#定义将秒转换为时分秒格式的函数
time_list=[]
iftime_init/3600>1:
time_h=int(time_init/3600)
time_m=int((time_init-time_h*3600)/60)
time_s=int(time_init-time_h*3600-time_m*60)
time_list.append(str(time_h))
time_list.append('h')
time_list.append(str(time_m))
time_list.append('m')
eliftime_init/60>1:
time_m=int(time_init/60)
time_s=int(time_init-time_m*60)
time_list.append(str(time_m))
time_list.append('m')
else:
time_s=int(time_init)
time_list.append(str(time_s))
time_list.append('s')
time_str=''.join(time_list)
returntime_str
if__name__=="__main__":
process=.0
start=time.time()
foriinrange(total_num):
···
···
···
ifprocess<(i*1.0/total_num):
ifprocess!=0:
end=time.time()
use_time=end-start
all_time=use_time/process
res_time=all_time-use_time
str_ues_time=time_change(use_time)
str_res_time=time_change(res_time)
print("Percentageofprogress:%.0f%%Usedtime:%sResttime:%s"%(process*100,str_ues_time,str_res_time))
process=process+0.01
总结
以上所述是小编给大家介绍的python程序运行进程、使用时间、剩余时间显示功能的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。