Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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 (106k 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. 

Related questions

0 votes
1 answer
+12 votes
3 answers
asked May 26, 2019 in Java by tara92 (920 points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...