0 votes
1 view
in Python by (20.2k points)

Is there a good way to do the following?

I wrote a simple console app to upload and download files from an FTP server using the ftplib.

Each time some data chunks are downloaded, I want to update a text progress bar, even if it's just a number.

But I don't want to erase all the text that's been printed to the console. (Doing a "clear" and then printing the updated percentage.)

1 Answer

0 votes
by (50.6k points)

To write text Progress Bar in the Console you can do write using '\r' which will move the cursor back to the beginning of the line.

Below is the code that displays a percentage counter:

import time

import sys

for i in range(100):

     time.sleep(1)

     sys.stdout.write("\r%d%%" % i)

     sys.stdout.flush()

image

This is just one screen-shot of the code while producing output. 

...