[Tutor] updating a print statement

Kent Johnson kent37 at tds.net
Mon Dec 10 20:43:53 CET 2007

Bryan Fodness wrote:
> I have a print statement in a for loop so I can watch the progress
> for line in file(file):
>     the_line = line.split()
>     if the_line:
>         print ("Index = %.2f") %index
> Is there a way that only one line will be output and the variable is 
> updated rather than one line for every index.

I'm not sure I understand what you are asking. index is never updated in 
the loop above.

If you want to overwrite the same line on the console, try
   print "\rIndex = %.2f" % index,

note ----^

You might need some extra spaces at the end of the print to 'erase' a 
longer previous line.


More information about the Tutor mailing list