Last active
November 30, 2017 16:11
-
-
Save miyouzi/0b19ca22037f585d0156e021728c9a5d to your computer and use it in GitHub Desktop.
Python 简易进度条
This file contains 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
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