mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
73360a3e61
commit
6ec099658a
2 changed files with 29 additions and 32 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue