Tqdm shows the progress for the generator. I know the length

I iterate over a large file that I know of, but I lazily process it because it is too large to fit in memory. I would like to be able to use tqdm to track my progress through the file, but since it cannot get the total number of examples from the generator that I use, the only thing it shows is the estimated iterations / sec. Is there a way to tell tqdm how many elements it will loop on the sum so that I can get some other statistics?

+6
source share
1 answer

You can pass the length to the total argument to make it work.

Example:

from tqdm import tqdm length = 1000000 generator = (3 * n for n in range(length)) # just doing something random for n in tqdm(generator, total=length): pass 
+11
source

Source: https://habr.com/ru/post/1014630/


All Articles