file write question

Robb Lane (SL name) rdrink at gmail.com
Sat Jan 26 22:02:38 EST 2008


I have written a script which:
- opens a file
- does what it needs to do, periodically writing to the file... for a
few hours
- then closes the file when it's done
So my question is:
Would it be better to 'open' and 'close' my file on each write cycle?
e.g.
def writeStuff(content):
     myFile = open('aFile.txt', 'a+')
     myFile.write(content)
     myFile.close()

... or just leave it till it's done?
I don't need to use the file contents until the script is done
(although it would be nice... just to check it while it's working), so
just curious what people think is the better method.
- rd



More information about the Python-list mailing list