StringIO proposal: add __iadd__

Erik Max Francis max at alcyone.com
Sun Jan 29 23:31:29 CET 2006


Paul Rubin wrote:

> I've always found the string-building idiom
> 
>   temp_list = []
>   for x in various_pieces_of_output(): 
>      v = go_figure_out_some_string()
>      temp_list.append(v)
>   final_string = ''.join(temp_list)
> 
> completely repulsive.   As an alternative I suggest
> 
>    temp_buf = StringIO()
>    for x in various_pieces_of_output(): 
>       v = go_figure_out_some_string()
>       temp_buf += v
>    final_string = temp_buf.getvalue()
> 
> here, "temp_buf += v" is supposed to be the same as "temp_buf.write(v)".
> So the suggestion is to add a __iadd__ method to StringIO and cStringIO.
> 
> Any thoughts?

Why?  StringIO/cStringIO have file-like interfaces, not sequences.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   The opinion of the strongest is always the best.
   -- Jean de la Fontaine



More information about the Python-list mailing list