美文网首页
Python打印进度条

Python打印进度条

作者: 遥远的清平湾 | 来源:发表于2019-02-18 08:12 被阅读0次

    原创,转载请注明出处,谢谢。

    定义进度条函数

    import time
    
    def process_bar(percent, start_str='', end_str='', total_length=20):
        bar = ''.join(['='] * int(percent * total_length)) + '>'
        bar = '\r' + start_str + '{:0>4.1f}% ['.format(percent*100) + bar.ljust(total_length) + ']' + end_str
        print(bar, end='', flush=True)
    
    

    调用

    for i in range(100):
        time.sleep(0.1)
        # t代表train, v代表validate
        end_str = ' - used: %s - loss: t%.4f/\033[0;34mv%.4f\033[0m (best: t%.4f/\033[0;34mv%.4f\033[0m) - acc: t%.0f%% (best: t%.0f%%)' % ('01:20:34', 0.12, 0.11, 0.08, 0.03, 98, 97)
        process_bar(i/100, start_str='', end_str=end_str, total_length=20)
    
    

    运行效果

    99.0% [===================>] - used: 01:20:34 - loss: t0.1200/v0.1100 (best: t0.0800/v0.0300) - acc: t98% (best: t97%)
    
    运行效果截图.PNG

    注:
    Python打印带颜色的字体可参考
    https://www.cnblogs.com/easypython/p/9084426.html
    https://www.cnblogs.com/ping-y/p/5897018.html

    如果解决了你的问题,就赞一个吧,让我知道有没有帮到你,谢谢!

    相关文章

      网友评论

          本文标题:Python打印进度条

          本文链接:https://www.haomeiwen.com/subject/vyyoeqtx.html