0 votes
1 view
in Python by (47.8k 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 (107k 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
2 answers
asked May 26, 2019 in Java by tara92 (920 points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 4, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...