目前,我正在研究文件读取程序,老板希望在执行过程中获得实时进度。 但是我的代码不起作用。在下面,我设法使代码易于阅读。如何使用生成器自动获取进度百分比,或者应该捕获“打印”流?谁能帮我?
import numpy as np
def Read_Pls():
every_step=0
total_step=0
for i in np.range(0,4): # I have 4 files
total_step = round(i/4*100 , 2)
yield(total_step)
for m in np.arange(0,8):
t=m
if 15>0:
for j in np.arange(0,15): # each file has 15 parts to analysis
every_step = round(j/15*100 , 2)
yield(every_step)
if __name__=="main":
for i in np.arange(0,100): #wishes it to proceed 100 times
T=Read_Pls()
print("total: ", total_step)
print("single file", every_step)
next(T)