How to overwrite the previous print to stdout in python?

后端 未结 16 1663
别那么骄傲
别那么骄傲 2020-11-22 09:46

If I had the following code:

for x in range(10):
     print x

I would get the output of

1
2
etc..

What I

16条回答
  •  醉话见心
    2020-11-22 10:33

    Since I ended up here via Google but am using Python 3, here's how this would work in Python 3:

    for x in range(10):
        print("Progress {:2.1%}".format(x / 10), end="\r")
    

    Related answer here: How can I suppress the newline after a print statement?

提交回复
热议问题