提交 ddeaf4e6 编写于 作者: 盼小辉丶's avatar 盼小辉丶

上传新文件

上级 45382d22
import shutil, sys
import time
def progressbar(func):
def _func_with_progress(*args, **kwargs):
max_width, _ = shutil.get_terminal_size()
gen = func(*args, **kwargs)
while True:
try:
progress = next(gen)
except StopIteration as exc:
sys.stdout.write('\n')
return exc.value
else:
message = '[%s] {}%%'.format(progress)
bar_width = max_width - len(message) + 3
filled = int(round(bar_width / 100.0 * progress))
spaceleft = bar_width - filled
bar = '=' * filled + ' ' * spaceleft
sys.stdout.write((message+'\r') % bar)
sys.stdout.flush()
@progressbar
def wait(seconds):
start = time.time()
step = seconds / 100.
for i in range(1, 101):
time.sleep(step)
yield i
return time.time() - start
if __name__ == '__main__':
print("Waiting", wait(4))
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册