python: print using carriage return and comma not working python: print using carriage return and comma not working python python

python: print using carriage return and comma not working


In the first case, some systems will treat \r as a newline. In the second case, you didn't flush the line. Try this:

sys.stdout.write('{0} imported\r'.format(tot))sys.stdout.flush()

Flushing the line isn't necessary on all systems either, as Levon reminds me -- but it's generally a good idea when using \r this way.


If you want to overwrite your last line you need to add \r (character return) and end="" so that you do not go to the next line.

values = range(0, 100)for i in values:    print ("\rComplete: ", i, "%", end="")print ("\rComplete: 100%")


I prefer to use the solution of Jan but in this way:

values = range(0, 101)for i in values:  print ("Complete: ", i, "%", end="\r")print ()