Python to print out status bar and percentage

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

To implement a status bar like below:

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

20条回答
  •  旧时难觅i
    2020-11-28 01:10

    Easiest is still

    import sys
    total_records = 1000
    for i in range (total_records):
        sys.stdout.write('\rUpdated record: ' + str(i) + ' of ' + str(total_records))
        sys.stdout.flush()
    

    Key is to convert the integer type to string.

提交回复
热议问题