I am new to python and am writing some scripts to automate downloading files from FTP servers, etc. I want to show the progress of the download, but I want it to stay in the same position, such as:
output:
Downloading File FooFile.txt [47%]
I'm trying to avoid something like this:
Downloading File FooFile.txt [47%]
Downloading File FooFile.txt [48%]
Downloading File FooFile.txt [49%]
How should I go about doing this?
Duplicate: How can I print over the current line in a command line application?
A neat solution that has been working for me is:
The
sys.stdout.flush
is important otherwise it gets really clunky and theprint("")
on for loop exit is also important.UPDATE: As mentioned in the comments,
print
also has aflush
argument. So the following will also work:You can also use the carriage return: