Python如何在控制台输出进度条

效果如下图所示:

欸呦图丢了

代码

import time
def print_bar(string:str,per:float,new_line=False):
    twer=round(max(0.,min(1.,per))*20)
    print(
        '%s%s: [%s%s] %s%%'%(
            '' if new_line else '\033[A',
            string,
            '='*twer,
            ' '*(20-twer),
            round(per*100)
            )
        )
epochs=350
for i in range(epochs):
    print_bar('training',i/epochs,i==0)
    time.sleep(0.05)

おすすめ

転載: blog.csdn.net/dscn15848078969/article/details/119719330
おすすめ