Currently I am working on a file reading program and the boss wants to get the real-time progress while executing. But my code doesn’t work. Below there, I managed to make the code simple to read. How can I get the progress percentage automatically by using generators, or maybe I should capture the “print” stream? Can anyone help me?
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)