Skip to content

Instantly share code, notes, and snippets.

@miyouzi
Last active November 30, 2017 16:11
Show Gist options
  • Save miyouzi/0b19ca22037f585d0156e021728c9a5d to your computer and use it in GitHub Desktop.
Save miyouzi/0b19ca22037f585d0156e021728c9a5d to your computer and use it in GitHub Desktop.
Python 简易进度条
def show_process(total):
# 生成器形式
# 任务进度条,total 是总任务数,每完成一步 next()
# 问题:进度太快会鬼畜,快到极致直接 100%
for i in range(total + 1):
k = i + 1
sys.stdout.write('\r')
sys.stdout.write(
"%3s%% |%s%s|" % (int(k / total * 100), int(k / total * 50) * '#', (50 - int(k / total * 50)) * ' '))
sys.stdout.flush()
if k == total:
print()
yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment