SF patch #907403: Improvements to cStringIO.writelines()

The writelines() method now accepts any iterable argument and writes
the lines one at a time rather than using ''.join(lines) followed by
a single write.  Results in considerable memory savings and makes
the method suitable for use with generator expressions.
This commit is contained in:
Raymond Hettinger 2004-03-08 18:17:31 +00:00
parent 73360a3e61
commit 6ec099658a
2 changed files with 29 additions and 32 deletions

View file

@ -178,8 +178,10 @@ class StringIO:
self.len = newpos
self.pos = newpos
def writelines(self, list):
self.write(''.join(list))
def writelines(self, iterable):
write = self.write
for line in iterable:
write(line)
def flush(self):
_complain_ifclosed(self.closed)