While in-progress
> python test-counting.py
==== Progress: 33.33% ====
> python test-counting.py
==== Progress: 50.0% =====
Final resting output:
> python test-counting.py
==== Progress: 100.0% ====
done :)
import time | |
some_list = [1,2,3,4,5,6] | |
counter = 0 | |
for file in some_list: | |
counter += 1 | |
percent = round((counter/len(some_list))*100, 2) | |
message = "==== Progress: " + str(percent) + "% ====" | |
if percent < 100: | |
# this line ending and buffer-flush allow us to re-write over this line again | |
print(message, end='\r', flush=True) | |
else: | |
# once we reach 100%, we won't want to rewrite the line again | |
print(message) | |
time.sleep(1.5) | |
# prints on its own line | |
print("done :)") |
Related: https://gist.github.com/matthewpoer/10183d4ac7b75e8bf0fc48a8c7d0a759