diff options
| author | Raymond Hettinger <python@rcn.com> | 2004-03-08 18:17:31 +0000 |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2004-03-08 18:17:31 +0000 |
| commit | 6ec099658ab49ed6d3c2861e437fe659e1c7037f (patch) | |
| tree | 2a8f9f3e3192bba966382e4a473092d1f376f3f6 /Lib/StringIO.py | |
| parent | 73360a3e61274ffcc4c9fc3d09746bd6603e92a5 (diff) | |
| download | cpython-git-6ec099658ab49ed6d3c2861e437fe659e1c7037f.tar.gz | |
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/StringIO.py')
| -rw-r--r-- | Lib/StringIO.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py index f35054e800..9b79a88f0b 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) |
