I am new to Python, but I didn't know this til yet. I have a basic program inside a for loop, that requests data from a site and saves it to a text file But when I checked inside my task manager I saw that the memory usage only increase? This might be a problem for me when running this for a long time. Is it standard for Python to do this or can you change it? Here is a what the program basically is
savefile = open("file.txt", "r+")
for i in savefile:
#My code goes here
savefile.write(i)
#end of loop
savefile.close()
Python does not write to file until you call .close() or .flush() or until it hits a specified buffer size. This question might help you: How often does python flush to a file?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With