【发布时间】:2019-08-21 07:18:51
【问题描述】:
我的代码中有三个进度条(1 个主进度条和 2 个子进度条)。我需要在新行中一一显示这些进度条。
我已经尝试在函数中包含新行,但那会为每次迭代创建一个新行,看起来不太好。
#Progress Bar
def progress(count, total, status=''):
bar_len = 40
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.flush()
sys.stdout.write('\r[%s] %s%s - %s\r' % (bar, percents, '%', status))
sys.stdout.flush()
sys.stdout.write("\r")
def sub_progress_source(count, total, status=''):
bar_len = 40
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.flush()
sys.stdout.write('\r\n\t[%s] %s%s - %s\r' % (bar, percents, '%', status))
sys.stdout.flush()
sys.stdout.write("\r")
def sub_progress_target(count, total, status=''):
bar_len = 40
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.flush()
sys.stdout.write('\r\n\t[%s] %s%s - %s\r' % (bar, percents, '%', status))
sys.stdout.flush()
sys.stdout.write("\r")
[====------](Main Progress Bar)
[====-----](Sub Progress Bar 1)
[=======--](Sub Progress Bar 2)
【问题讨论】:
标签: python progress-bar