[Python-3000] encoding hell

Anders J. Munch 2006 at jmunch.dk
Sun Sep 3 19:11:27 CEST 2006

tomer filiba wrote:
 > my solution would be completely leaving seek() and tell() out of the
 > 3rd layer -- it's a byte-level operation.
 > anyone thinks differently? if so, what's your solution?

seek and tell are a poor mans sequence.  I would have nothing by those

I would have input streams, output streams and sequences, and I
wouldn't mix the three.  FileReader would be an InputStream,
FileWriter would be an OutputStream.  FileBytes would support the
sequence protocol, mimicking bytes objects.  It would support
random-access read and write using __getitem__ and __setitem__,
allowing slice assignment for slices of equal size.  And there would
be append() to extend the file, and partial __delitem__ support for

Looking at your iostack2 Stream class, no sooner do you introduce the
key methods read and write, than you supplement them with capability
queries readable and writable that check whether these methods may
even be called.  IMO this is a clear indication that these methods
really want to be refactored into separate classes.

I think you'll find that separating input, output and random access
into three separate ADTs will much simplify BufferingLayer (even
though you'll need three of them).  At least if you intend to take
interactions between reads and writes into account.


More information about the Python-3000 mailing list