How do I use a progress bar when my script is doing some task that is likely to take time?
For example, a function which takes some time to complete and returns
I used format()
method to make a load bar. Here is my solution:
import time
loadbarwidth = 23
for i in range(1, loadbarwidth + 1):
time.sleep(0.1)
strbarwidth = '[{}{}] - {}\r'.format(
(i * '#'),
((loadbarwidth - i) * '-'),
(('{:0.2f}'.format(((i) * (100/loadbarwidth))) + '%'))
)
print(strbarwidth ,end = '')
print()
Output:
[#######################] - 100.00%