zoukankan      html  css  js  c++  java
  • python progress包 介绍

    Project description

    Easy progress reporting for Python

    Demo

    Bars

    There are 7 progress bars to choose from:

    • Bar
    • ChargingBar
    • FillingSquaresBar
    • FillingCirclesBar
    • IncrementalBar
    • PixelBar
    • ShadyBar

    To use them, just call next to advance and finish to finish:

    from progress.bar import Bar
    
    bar = Bar('Processing', max=20)
    for i in range(20):
        # Do some work
        bar.next()
    bar.finish()
    

    or use any bar of this class as a context manager:

    from progress.bar import Bar
    
    with Bar('Processing', max=20) as bar:
        for i in range(20):
            # Do some work
            bar.next()
    

    The result will be a bar like the following:

    Processing |#############                   | 42/100
    

    To simplify the common case where the work is done in an iterator, you can use the iter method:

    for i in Bar('Processing').iter(it):
        # Do some work
    

    Progress bars are very customizable, you can change their width, their fill character, their suffix and more:

    bar = Bar('Loading', fill='@', suffix='%(percent)d%%')
    

    This will produce a bar like the following:

    Loading |@@@@@@@@@@@@@                   | 42%
    

    You can use a number of template arguments in message and suffix:

    NameValue
    index current value
    max maximum value
    remaining max - index
    progress index / max
    percent progress * 100
    avg simple moving average time per item (in seconds)
    elapsed elapsed time in seconds
    elapsed_td elapsed as a timedelta (useful for printing as a string)
    eta avg * remaining
    eta_td eta as a timedelta (useful for printing as a string)

    Instead of passing all configuration options on instatiation, you can create your custom subclass:

    class FancyBar(Bar):
        message = 'Loading'
        fill = '*'
        suffix = '%(percent).1f%% - %(eta)ds'
    

    You can also override any of the arguments or create your own:

    class SlowBar(Bar):
        suffix = '%(remaining_hours)d hours remaining'
        @property
        def remaining_hours(self):
            return self.eta // 3600
    

    Spinners

    For actions with an unknown number of steps you can use a spinner:

    from progress.spinner import Spinner
    
    spinner = Spinner('Loading ')
    while state != 'FINISHED':
        # Do some work
        spinner.next()
    

    There are 5 predefined spinners:

    • Spinner
    • PieSpinner
    • MoonSpinner
    • LineSpinner
    • PixelSpinner

    Installation

    Download from PyPi

    pip install progress
    

    Other

    There are a number of other classes available too, please check the source or subclass one of them to create your own.

    License

    progress is licensed under ISC




    如果这篇文章帮助到了你,你可以请作者喝一杯咖啡

  • 相关阅读:
    2021“MINIEYE杯”中国大学生算法设计超级联赛2
    2021“MINIEYE杯”中国大学生算法设计超级联赛1
    2021牛客暑期多校训练营3
    2021牛客暑期多校训练营1
    对点分治的一些新理解
    使用均摊分析证明Splay复杂度
    从实际项目中学设计模式:策略模式与模板模式的应用
    ueditor编辑器html模式下无法保存内容
    记录一次项目开发中遇到的问题
    加解密代码
  • 原文地址:https://www.cnblogs.com/sddai/p/14898545.html
Copyright © 2011-2022 走看看