Writing Log CSV (Efficiently)

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Mon Apr 16 09:20:42 EDT 2007


Hello Guys,

 

I'm looking to write a Log file which will be CSV based, and there is a good
possibility that it'll get quite busy once its up and running, so I'm
looking for the most efficient way to achieve it. Whilst I'm sure i could do
something like this.

 

              myfile = open("Logs/Application.txt", "w")

              myfile.write('col1, col2, col3, col4, col5')

              myfile.close

 

But I'm a little apprehensive that open() and close() on a very regular
basis is just going to cause issues. I'm also a little worried that we'll
end up with 'race' type conditions and things going missing.

 

So my next thought was to just have an open object for the file, and then
perform multiple rights, until I need to send the report file somewhere
else, at which point I would close it. This in itself causes more issues as
we're running in a buffer which is just going to eat my memory, and as this
is on an embedded system which may lose power, we'd be kissing good bye to
all the logs until that point.

 

What would you guys suggest to be the most efficient way to handle this?

 

Thanks,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070416/f0974097/attachment.html>


More information about the Python-list mailing list