Python Progress Bar

后端 未结 30 2263
礼貌的吻别
礼貌的吻别 2020-11-22 06:13

How do I use a progress bar when my script is doing some task that is likely to take time?

For example, a function which takes some time to complete and returns

30条回答
  •  臣服心动
    2020-11-22 07:06

    I really like the python-progressbar, as it is very simple to use.

    For the most simple case, it is just:

    import progressbar
    import time
    
    progress = progressbar.ProgressBar()
    for i in progress(range(80)):
        time.sleep(0.01)
    

    The appearance can be customized and it can display the estimated remaining time. For an example use the same code as above but with:

    progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',
                                                progressbar.Percentage(), ' ',
                                                progressbar.ETA()])
    

提交回复
热议问题