StringIO proposal: add __iadd__

Raymond Hettinger python at rcn.com
Tue Jan 31 12:28:04 EST 2006


[Raymond Hettinger]
> > The StringIO API needs to closely mirror the file object API.
> > Do you want to change everything that is filelike to have +=
> > as a synonym for write()?

[Paul Rubin]
> Why would they need that?

Polymorphism

> StringIO objects have getvalue() but other
> file-like objects don't.  What's wrong with __iadd__ being another
> StringIO-specific operation?

The getvalue() method isn't a synonym for another method in the file
object API. Its design capitalizes on properties unique to StringIO
(direct access to the full buffer without rewinding the file pointer).

In contrast, the __iadd__() method is a synonym for write(). Its use
cases are the same for both StringIO and file objects.




More information about the Python-list mailing list