有很多程序運行時間比較長,如果不將運行過程輸出將很難判斷程序運行的時間。下邊這段程序?qū)凑丈蠄D所示的格式輸出程序運行進程、已用時間、剩余時間。
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比石鼓網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式石鼓網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋石鼓地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。def time_change(time_init): #定義將秒轉(zhuǎn)換為時分秒格式的函數(shù) time_list = [] if time_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 ') elif time_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) return time_str if __name__=="__main__": process = .0 start = time.time() for i in range(total_num): ··· ··· ··· if process < (i*1.0/total_num): if process != 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("Percentage of progress:%.0f%% Used time:%s Rest time:%s "%(process*100,str_ues_time,str_res_time)) process = process + 0.01