It would be nice to be able to easily implement a progress bar when you want to visualize the progress of iterative processing, such as an installer or file downloader.
I also wanted to display the progress of iterative processing in a slightly better way. There is a library called tqdm, and when I actually used it, I was able to implement it very simply.
import time
import tqdm
#Standard output of progress bar at the same time as iterative processing
for _ in tqdm.tqdm(xrange(10)):
time.sleep(1)
To use it, just pass the iterator to the `` `tqdm.tqdm``` function. Each time you iterate over the returned iterator object, the standard output shows the progress.
0%| | 0/10 [00:00<?, ?it/s]
10%|█ | 1/10 [00:10<01:30, 10.00s/it]
20%|██ | 2/10 [00:20<01:20, 10.00s/it]
30%|███ | 3/10 [00:30<01:10, 10.00s/it]
40%|████ | 4/10 [00:40<01:00, 10.00s/it]
50%|█████ | 5/10 [00:50<00:50, 10.00s/it]
60%|██████ | 6/10 [01:00<00:40, 10.00s/it]
70%|███████ | 7/10 [01:10<00:30, 10.00s/it]
80%|████████ | 8/10 [01:20<00:20, 10.00s/it]
90%|█████████ | 9/10 [01:30<00:10, 10.00s/it]
100%|██████████| 10/10 [01:40<00:00, 10.00s/it]
This completes the progress bar implementation. It's very easy.
In the above result, all the progress displays for each round are displayed, but in reality, the next display will be displayed in a form that overwrites the previous display.
Recommended Posts