I'm pretty new with Python, but I am trying to do something which I believe is a pretty simple thing. Nevertheless it has been bothering me for quite a while.
I have a code that does a certain number of iterations and I want to print, on the same line, a status of the progress.
I tried the following
y=1000000
for x in range(y):
if x % 100000 == 0 and x!=0 or x==y :
print " Iteration %d out of %d\r" % (x,y)
but what I get is not a carriage return but simply
Iteration 100000 out of 1000000
Iteration 200000 out of 1000000
Iteration 300000 out of 1000000
Iteration 400000 out of 1000000
Iteration 500000 out of 1000000
...
printed out at video.
The funny thing is that if I do
for x in range(1000000):
print "%d\r" % x,
it does the job. Does anybody knows why?