Python Progress Bar

后端 未结 30 2588
礼貌的吻别
礼貌的吻别 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:08

    Try PyProg. PyProg is an open-source library for Python to create super customizable progress indicators & bars.

    It is currently at version 1.0.2; it is hosted on Github and available on PyPI (Links down below). It is compatible with Python 3 & 2 and it can also be used with Qt Console.

    It is really easy to use. The following code:

    import pyprog
    from time import sleep
    
    # Create Object
    prog = pyprog.ProgressBar(" ", "", 34)
    # Update Progress Bar
    prog.update()
    
    for i in range(34):
        # Do something
        sleep(0.1)
        # Set current status
        prog.set_stat(i + 1)
        # Update Progress Bar again
        prog.update()
    
    # Make the Progress Bar final
    prog.end()
    

    will produce:

    Initial State:
    Progress: 0% --------------------------------------------------
    
    When half done:
    Progress: 50% #########################-------------------------
    
    Final State:
    Progress: 100% ##################################################
    

    I actually made PyProg because I needed a simple but super customizable progress bar library. You can easily install it with: pip install pyprog.

    PyProg Github: https://github.com/Bill13579/pyprog
    PyPI: https://pypi.python.org/pypi/pyprog/

提交回复
热议问题