1

Possible Duplicate:
Python Progress Bar
Text Progress Bar in the Console

So I'm working on a basic program and I'm trying to make two things:

  1. A Loading... text line where the dots increase in this manner:

    Loading.

    Loading..

    Loading...

    Loading.

    Loading..

    Loading...

  2. An increasing percent in one line:

    1% Complete...

    3% Complete...

    etc.

So, my question is how do I remove/replace printed text? I want these things to happen on one line. For the first example, how do I replace the 3 dots with just 1, or just erase the 2 on the end (without going to the next line)? For the second example, how do I make the percent increase while staying on the same line?

Community
  • 1
  • 1
Hi_910
  • 11
  • 2

1 Answers1

1
>>> for i in range(100):
...    time.sleep(1)
...    sys.stdout.write("\r%d%%" %i)    # or print >> sys.stdout, "\r%d%%" %i,
...    sys.stdout.flush()
... 

This will help you with the percentage.

dandan78
  • 13,328
  • 13
  • 64
  • 78
Pradyumna
  • 167
  • 2
  • 12