summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-08 18:17:31 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-08 18:17:31 (GMT)
commit6ec099658ab49ed6d3c2861e437fe659e1c7037f (patch)
tree2a8f9f3e3192bba966382e4a473092d1f376f3f6 /Lib
parent73360a3e61274ffcc4c9fc3d09746bd6603e92a5 (diff)
downloadcpython-6ec099658ab49ed6d3c2861e437fe659e1c7037f.zip
cpython-6ec099658ab49ed6d3c2861e437fe659e1c7037f.tar.gz
cpython-6ec099658ab49ed6d3c2861e437fe659e1c7037f.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/StringIO.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
index f35054e..9b79a88 100644
--- a/Lib/StringIO.py
+++ b/Lib/StringIO.py
@@ -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)