This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Unsupported provider

classification
Title: Improvements to cStringIO.writelines()
Type: Stage:
Components: Extension Modules Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: nnorwitz, rhettinger
Priority: normal Keywords: patch

Created on 2004-03-01 09:35 by rhettinger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cStringIO.diff rhettinger, 2004-03-01 09:35 cStringIO.diff
Messages (3)
msg45437 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-03-01 09:35
Currently, cStringIO.writelines() only accepts a 
sequence argument and it passes that argument 
internally to str.join() to construct a large temporary 
string before writing.

The patch allows the method to accept any iterable 
argument and for the lines to be written one at a time 
which cuts memory utilization in half.

The result is especially valuable when used with 
generators or itertools because the strings are 
constructed on the fly rather than all at once.
msg45438 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-03-08 03:25
Logged In: YES 
user_id=33168

I don't see any problems with the new code.  One nit though,
I hate using l as a variable name because it's difficult to
tell if it's an l (ell) or a 1 (one).  I realize O_cwrite
uses l.  I'm not against n though. :-)

Should the docstring be updated?  It says the parameter is a
sequence_of_strings.  I'm not sure if it would be good to call
it an iterable_of_strings.  That sounds funny.

I think it's good that it takes an iterable.  That makes it
more like
StringIO.

Should StringIO.writelines() be changed?  It currently does:
 self.write(''.join(list))
msg45439 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-03-08 18:26
Logged In: YES 
user_id=80475

Thanks for the second review.

As requested:
* Changed 'l' to 'n'.
* Made a parallel change to StringIO.py.
* Borrowed a docstring mentioning iterables from
file.writelines.

Checked-in as:
Lib/StringIO.py 1.34
Modules/cStringIO.c 2.47

History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 39994
2004-03-01 09:35:03rhettingercreate