I made a regular notification function for information from the trend repository on github, and this is a series that introduces the interesting repositories that I discovered through it. The table of contents is here.
This time, I will introduce an interesting progress bar called alive-progress. I think that most people use tqdm when it comes to python's progress bar, but alive-progress was created for those who want to use a slightly playful progress bar. It looks like the one below.
First, install alive-progress.
pip install alive-progress
If you want it to behave like the GIF above, you can do it with the code below.
from alive_progress import alive_bar, config_handler
import time
from tqdm import tqdm
def main():
for x in 5000, 6000:
with alive_bar(x, bar='checks', spinner='notes') as bar:
for i in range(5000):
time.sleep(.001)
bar()
# show_bars()
# show_spinners()
if __name__ == '__main__':
main()
It's okay if you pass the number of loops as the first argument of the with statement. After that, if you select the type of bar at bar ='' and the display on the right side of bar with spinner ='', it will look like a GIF. A check mark is selected for bar and a note is selected for spinner. Then put bar () at the end of the for statement and you're done. Valuations for bar and spinners are displayed by show_bars () and show_spinners (), respectively. List of bars List of spinner
I compared it with the code below.
from alive_progress import alive_bar, config_handler
import time
from tqdm import tqdm
def main():
print("~~Using tqdm~~")
for i in 1000, 2000:
for x in tqdm(range(1000)):
time.sleep(.001)
print("~~Using active-progress")
for x in 1000, 2000:
with alive_bar(x, bar='checks', spinner='notes') as bar:
for i in range(1000):
time.sleep(.001)
bar()
The result looks like the one below. When the passed value isn't completely looped (2000 this time), active-progress is signaled by a (!) Mark. For simplicity, tqdm is good, but I like active-progress (laughs).
I'm looking forward to writing the code that turns the loop (laughs).