How to rewrite output in terminal

后端 未结 4 1025
孤城傲影
孤城傲影 2020-12-25 13:22

I have a Python script and I want to make it display a increasing number from 0 to 100% in the terminal. I know how to print the numbers on the terminal but how can I \"rewr

4条回答
  •  长情又很酷
    2020-12-25 13:56

    Based on this answer, but without the terminal controller:

    import time
    import sys
    for i in range(100):
        sys.stdout.write("Downloading ... %s%%\r" % (i))
        sys.stdout.flush()
        time.sleep(1)
    

    Tested on GNOME terminal (Linux) and Windows console.

    Tip: Don't run this example in IDLE editor.

提交回复
热议问题