file write question
thebjorn
BjornSteinarFjeldPettersen at gmail.com
Sun Jan 27 03:54:18 EST 2008
On Jan 27, 4:02 am, "Robb Lane (SL name)" <rdr... at gmail.com> wrote:
> 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
Sounds like a classic case for a database to me (long running process
producing sporadic output that you might want to tinker with as it's
being produced). Python 2.5 comes with sqlite3 included...
-- bjorn
More information about the Python-list
mailing list