Title: Improvements to cStringIO.writelines()
Type: Stage:
Components: Extension Modules Versions: Python 2.4
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 2004-03-08 18:26 by rhettinger. This issue is now closed.

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 

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

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

Thanks for the second review.

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

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

Date User Action Args
2004-03-01 09:35:03rhettingercreate