Most efficient way to write data out to a text file?

Bengt Richter bokr at oz.net
Thu Jun 27 12:36:23 EDT 2002


On Thu, 27 Jun 2002 14:09:09 GMT, candiazoo at attbi.com wrote:

>I am a newbie... this is my first Python "project" so I am probably writing
>horribly inefficient code...  I have never used the profiler but I'll try it!
>
>I am not opening/closing the file each time.  I am extracting 700000 rows from a
>mysql database, extracting additional data from our primary, Oracle database per
Are you by chance opening and closing your mysql connection for each row? Easy
to do if you just wrote a quick get-me-one-row wrapper function and forgot to revise it.

>row, then stuffing each piece of data into a class which preformats the data (I
>need to output the data into a fixed format string/record for another
>application which reads them) and returns a single string... which I write out
>to the file.
>
If it's working, probably the best thing is to measure actual timing before optimizing.

Regards,
Bengt Richter



More information about the Python-list mailing list