Member-only story
🐍 Python | A very simple progress bar — tqdm
tqdm
derives from the Arabic word taqaddum (تقدّم) which can mean "progress," and is an abbreviation for "I love you so much" in Spanish (te quiero demasiado).
There are already quite few resources related to how to do things in tqdm()
, however they are all describing somewhat complex scenarios, and also differ in syntax. Whenever I was trying to apply these examples to my needs I couldn’t achieve desirable result. Well, I guess I’m just not that good at reading technical documentation.
So, here’s my 50 cents for a very basic scenario:
Let’s say you are writing a small python script that is counting how many hours you have worked in a month. Let’s say you have also provided a max hours boundary. And as the counter is increasing you would like to see a progress bar.
The screenshot shows the end result I wanted to achieve:
By default, tqdm shows a lot of information on the right-side of the progress bar so I had to customize it a bit to fit my needs.
with tqdm(range(0, max_hours), mininterval=10, unit='hrs',
bar_format='{l_bar}{bar}{n_fmt}hrs/{total_fmt}hrs',
desc="Counting hours..") as progressbar:
counter += hours # increase by 10 hours
progressbar.update(counter)