简体   繁体   中英

Print spills out when trying to print progress bar with '\r' in python

I am trying to build a simple progress bar in python, with '\\r' and end='':

In [1]: for i in range(100):
...:        print("\rUploading some sort of data: ", i, "/", 100, end='')
...:        time.sleep(0.1)

The expected out would be like:

Uploading some sort of data:  99 / 100

But it now gives me this:

Uploading some sort of data:  99 / 100/ 100 100100

(I am using Spyder and I am not encountering this issue with windows command, is it the problem of Spyder? and how should I solve this?)

Thanks!

I've just accidently succeed to figured out the issue by myself.

For unknown reasons, the ipython console in Spyder handles the print operation uncorrectly with comma , but correctly with placeholders or {}.format() :

在此输入图像描述

Thanks all!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM