writing to file very slow

sismex01 at hebmex.com sismex01 at hebmex.com
Wed Mar 26 09:55:45 EST 2003


I kinda skimmed over your code, and the problem isn't
the DB adaptor, it's the way you're building up your
data: you're concatenating a huge string and then
dumping it to the file, that's very slow.

Instead of concatenating strings like this (which is
used extensively):

	stringvar += something_else

use a list to accumulate data until you want to dump
it to the file, like this:

	listvar.append(something_else)

When you're ready to dump the data to the file, you
can either create a huge string ONCE and write that:

	filevar.write(''.join(listvar))

OR, you can iterate through the listvar and write
every individual string inside:

	for I in listvar: filevar.write(I)

HTH!

-gustavo





More information about the Python-list mailing list