How do I write output in same place on the console?


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:


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?

5/23/2017 12:10:26 PM

Accepted Answer

You can also use the carriage return:

sys.stdout.write("Download progress: %d%%   \r" % (progress) )
11/19/2012 12:01:12 PM

Use a terminal-handling library like the curses module:

The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow