0

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)
Qbz
  • 15
  • 4
  • 1
    `if 15>0:` ???? – Klaus D. Dec 06 '18 at 14:02
  • `print()` prints by default to whatever you have set as `sys.stdout`. IF this runs in a console, you'll see it right away (unless you redirect it somewhere else, ofc). – GPhilo Dec 06 '18 at 14:03
  • 1
    If you're asking "is there any way to tell how close an iterable is to completing while I'm iterating over it?", not in the general case. Iterables are perfectly capable of running forever, yielding an infinite number of values. You'd have to solve the Halting Problem if you wanted to deduce the progress of an arbitrary generator without running it to completion. – Kevin Dec 06 '18 at 14:06
  • 1
    If you're asking "I know I will only iterate over the first 100 elements of my iterable. How do I display and update an aesthetically pleasing progress bar each time through my loop?", consult [Python Progress Bar](https://stackoverflow.com/q/3160699/953482) – Kevin Dec 06 '18 at 14:08
  • @KlausD. Its a given number, which is not related to my question so I simplified it. – Qbz Dec 06 '18 at 14:41
  • @GPhilo The boss wants to see it in a Qt GUI, so another colleague used progress bar in Qt. – Qbz Dec 06 '18 at 14:42

0 Answers0