[Python-Dev] Single- vs. Multi-pass iterability

Greg Ewing greg@cosc.canterbury.ac.nz
Thu, 18 Jul 2002 11:39:05 +1200 (NZST)


Alex Martelli <aleax@aleax.it>:

> the file object's is the only example of "fat interface" problem
> in Python -- an interface that exposes a lot of methods, with many
> objects claiming they implement that interface but actually lying

Maybe the existing file object should be split up into
some number of other objects with smaller interfaces.

For example, instead of the file object actually accessing an
OS file itself, it could just be a wrapper around an
underlying "bytestream" object, which implements only
read() and write().

Then, instead of implementing your own file-like object,
you would implement a new bytestream object instead, and
wrap it in a standard file object. That would give you
all the flavours of access automatically without having
to implement them yourself and without lying about
anything.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+