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
Here's a short solution that builds the loading bar programmatically (you must decide how long you want it).
import time
n = 33 # or however many loading slots you want to have
load = 0.01 # artificial loading time!
loading = '.' * n # for strings, * is the repeat operator
for i in range(n+1):
# this loop replaces each dot with a hash!
print('\r%s Loading at %3d percent!' % (loading, i*100/n), end='')
loading = loading[:i] + '#' + loading[i+1:]
time.sleep(load)