[Python-3000] On PEP 3116: new I/O base classes
Bill Janssen
janssen at parc.com
Tue Jun 19 20:47:46 CEST 2007
A few comments here:
I'd get rid of "readinto", and just make the buffer an optional
argument to "read". If you keep "readinto", why not rename "write" to
"writefrom"?
The "seek" method on RawIOBase is awfully quaint and UNIX-y, what with
the "whence" argument. It could be made considerably more Pythonic by
splitting it into two methods:
.seek(POS: int)
where positive values for POS are from the beginning of the file, and
negative values of POS are from the end of the file, and
.nudge(POS: int)
where the value of POS, positive or negative, is from the current
location. Or call the two methods "seek_absolute" and "seek_relative".
Of course, you don't really need "nudge" if you have "tell".
Might even rename "seek" to "position". And I'd consider putting these
two methods in a separate mixin; lots of file-like things can't seek.
===============================================
``If and only if a RawIOBase implementation operates on an underlying
file descriptor, it must additionally provide a .fileno() member
function. This could be defined specifically by the implementation, or
a mix-in class could be used (need to decide about this).''
I'd suggest a mixin.
===============================================
TextIOBase: this seems an odd mix of high-level and low-level. I'd
remove "seek", "tell", "read", and "write". Remember that in Python,
mixins actually work, so that you can provide a file object that
combines several different I/O classes. And The Java-ish notion in
TextIOBase.read(), that you can specify a count for the number of
characters (or is that the number of UTF-8 bytes, etc... -- rich
source of subtle bugs), just doesn't work in practice. And the
"codecs" module already provides a way of doing this, for those who
feel the need. Stick to just "readline" and "writeline" for text I/O.
Bill
More information about the Python-3000
mailing list