in c and c++ there is a useful way to refresh an output line in printf and cout using \r meta command. So for example in the wget application the progress of the download is updated on the same output line of the screen. From an intital investigation python seems to lack this. Is this correct?
> in c and c++ there is a useful way to refresh an output line in printf > and cout using \r meta command. So for example in the wget application > the progress of the download is updated on the same output line of the > screen. From an intital investigation python seems to lack this. Is > this correct?
No. Well, I think you can't do it with print, but you can do this:
import sys import time
signs = "|/-\\" while 1: for i in signs: sys.stdout.write(i+"\r") sys.stdout.flush() time.sleep(0.2)
Jake wrote: > in c and c++ there is a useful way to refresh an output line in printf > and cout using \r meta command. So for example in the wget application > the progress of the download is updated on the same output line of the > screen. From an intital investigation python seems to lack this. Is > this correct?
Jake wrote: > in c and c++ there is a useful way to refresh an output line in printf > and cout using \r meta command. So for example in the wget application > the progress of the download is updated on the same output line of the > screen. From an intital investigation python seems to lack this. Is > this correct?
>>> for i in range(10000):
... print '\r',i,'and counting', ... 9999 and counting
(not obvious from the copy/paste of the output is that it also displayed the intervening numbers as it counted). The important thing is to end each print statement with a comma (or use sys.stdout.write).
"Jake" <jacob.hu...@gmail.com> wrote: > in c and c++ there is a useful way to refresh an output line in printf > and cout using \r meta command.
that's a control character that's printed to the terminal by printf/cout, not a "C or C++ meta command"
to print the same character in Python, use the same character escape:
print "\r", count,
(note that if this works or not depends on the terminal you're sending the output to. most ordinary terminals handle it just fine, but if you're sending output to an IDE console window, it may not work as expected)