Simple file writing techiques ...
Ganesan Rajagopal
rganesan at myrealbox.com
Wed Jul 19 08:18:58 EDT 2006
>>>>> cdecarlo <cdecarlo at gmail.com> writes:
> fout = open('somefile','w')
> for line in convertedData:
> fout.write("%s\n" % line)
> fout.close()
> -- or --
> fout = open('somefile','w')
> fout.write("%s" % '\n'.join(convertedData))
> fout.close()
> ... or maybe some hybrid of the two which writes chunks of the
> convertedData list out in one shot ...
The second option would be definitely faster.
> An issue that I'm probably most concerned with is scalabitiy, what if
> the file was huge, like some sort of log file.
Considering that you've already read in the whole file into a list, it's too
late to worry about scalability when writing out :-). Have you considered
the fileinput module?
Ganesan
--
Ganesan Rajagopal
More information about the Python-list
mailing list