> print "Percent completed:" + str(percent) + "\r"
>
> Which should send me back to the beginning of the line and overwrite
it
> with a new line. But instead I get:
>
> Percent completed: 50
> Percent completed: 51
Print always adds a newline unless you put a comma at the end.
Unfortunately that results in a character being lost too so I
recommend using a tab at the front like this:
for n in range(20):
print "\tAt line: %5s" % n
Also be aware that on sime systems \r is the newline character
in which case the method I use is to backspace the number of
characters occupied by my data (5 in the case above) using
\010.
Something like this slightly flawed example:
>>> def f():
... print "Label: ",
... for n in range(5):
... print "%s%3s" % ('\010' * 3, n),
...
I'll leave debugging it as an excercise for the reader! :-)
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor