jeppoo1
jeppoo1

Reputation: 698

Progress bar for writing text to a file (=how much time it takes to write to a file)

I am using Python 3.8.1 on Windows 10 and VSCode.

I have a simple program which writes a lot of text into a .txt file. The final file size of the .txt file is around 7MB so it takes quite a bit of time for writing the text into the file.

I have read other questions about progress bars but if I understood correctly, they need you to know how much time an operation requires and you have to determine the estimated time for the progress bar yourself, instead of the progress bar itself to automatically figure out how long an operation takes. On top of that, many of them focus on for/while loops and my script does not have a loop, it is just writing text in a file:

my_text = "Hello World, Hello World, Hello World"

text_file = open("Output.txt", "w", encoding = 'utf-8')
text_file.write(my_text)
text_file.close()

My question: is it possible to write code for a progress bar that finds out how long it takes for my program to write to a text file in seconds, and display that in the progress bar in percents and time remaining?

(e.g. Progress 40%/100% ======---------, 3.5MB/8MB written to file, 44 seconds remaining)

If this is not possible, how do I determine myself how long it takes to write the text to a file? Is there a script or package for writing a separate program for that?

Upvotes: 2

Views: 1859

Answers (1)

Alphy Sebastian
Alphy Sebastian

Reputation: 43

This might help you. Various approaches are outlined in the answers.

Python Progress Bar

Upvotes: -1

Related Questions