writing to file very slow

Andrew Dalke adalke at mindspring.com
Wed Mar 26 17:27:49 EST 2003


John Machin
> No, it's not what [the OP] wanted, and it's not a correct translation but
> the original is so god-awfully-obscure that you are forgiven :-)
>
> Here's his original, with two substitutions, and removing the str() --
> this makes it much clearer what is going down ...
>
>    for row in gotten_result:
>       var = ""
>       for y in range(numfields-1):
>          var += row[y] + '|'
>       var += row[numfields-1]
>       f.write(var)
>       f.write('\n')

Being lazy and not reading the other threads in detail...

This can be simplified and made faster with

    for row in gotten_result:
      f.write("|".join(row))
      f.write("\n")

(assuming numfields == len(row), else use join(row[:numfields]) )

                    Andrew
                    dalke at dalkescientific.com







More information about the Python-list mailing list