[Python-Dev] Re: Optional separatorargument for file.writelines()and StringIO.writelines() (original) (raw)

Raymond Hettinger python at rcn.com
Thu Feb 26 20:13:16 EST 2004


This is a big YES!

Actually, it's a big no. Alex, immediately and correctly pointed out that what is needed in a suffix rather than a separator and the way to get that is with a generator expression: f.writelines(x+'\n' for x in mylines).

I had been led astray because I was experimenting with using cStringIO.writelines() as a basis for implementing str.join() for general iterables without creating an intermediate tuple. Right now, ''.join(it) will unexpectedly consume much more memory than really needed.

Raymond Hettinger



More information about the Python-Dev mailing list