Python to print out status bar and percentage

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

To implement a status bar like below:

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

20条回答
  •  鱼传尺愫
    2020-11-28 01:24

    Per Steven C. Howell's comment on Mark Rushakoff's answer

    j = (i + 1) / n
    stdout.write('\r')
    stdout.write('[%-20s] %d%%' % ('='*int(20*j), 100*j))
    stdout.flush()
    

    where i is the current item and n is the total number of items

提交回复
热议问题