Python to print out status bar and percentage

后端 未结 20 1092
野的像风
野的像风 2020-11-28 01:01

To implement a status bar like below:

[==========                ]  45%
[================          ]  60%
[==========================] 100%

20条回答
  •  天涯浪人
    2020-11-28 01:24

    If you are developing a command line interface, I suggest you to take a look at click which is very nice:

    import click
    import time
    
    for filename in range(3):
        with click.progressbar(range(100), fill_char='=', empty_char=' ') as bar:
            for user in bar:
                time.sleep(0.01)
    

    Here the output you get:

    $ python test.py
      [====================================]  100%
      [====================================]  100%
      [=========                           ]   27%
    

提交回复
热议问题