Created
April 16, 2020 17:05
-
-
Save aasmpro/e961111ca93d174282ddae697b293891 to your computer and use it in GitHub Desktop.
progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
def progress(percent=0, width=30): | |
left = width * percent // 100 | |
right = width - left | |
print('\r[', '#' * left, ' ' * right, ']', | |
f' {percent:.0f}%', | |
sep='', end='', flush=True) | |
for i in range(101): | |
progress(i) | |
sleep(0.1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle | |
from time import sleep | |
def spin(data, duration=0.2, check=lambda: False): | |
for frame in cycle(data): | |
if not check(): | |
print('\r', frame, sep='', end='', flush=True) | |
sleep(duration) | |
else: | |
print('\r', '[OK] task done.', sep='', flush=True) | |
break | |
def check(): | |
global time, duration | |
time += duration | |
return time >= 3 | |
time = 0 | |
duration = 0.2 | |
spin(['... ',' ... ',' ... ',' ...',' ... ',' ... '], duration=duration, check=check) | |
print('program completed') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment