[Python-3000] io library/PEP 3116 bits

skip at pobox.com skip at pobox.com
Mon Jul 30 15:13:18 CEST 2007


I was looking at PEP 3116 to try and figure out what the newline keyword
argument was for (it was mentioned in a couple replies to some checkin
comments and I see it in io.py).  It's not really mentioned in the PEP as
far as I could tell other than this:

    Some new features include universal newlines and character set encoding
    and decoding.

The io.open() docstring has this to say:

      newline: optional newlines specifier; must be None, '\n' or '\r\n';
               specifies the line ending expected on input and written on
               output.  If None, use universal newlines on input and
               use os.linesep on output.

Shouldn't '\r' be provided as an option for Macs?  Also, shouldn't the "U"
mode flag be discarded (2to3 could maybe do this)?  Is this particular bit
of backwards compatibility all that necessary?

The other thing I wanted to comment on is the default value for n in the
various read methods.  In some places it's -1 (why not zero? *), but in
other places it's None, with presumably the same meaning.  Shouldn't this be
consistent across all read methods?  The couple read methods mentioned in
PEP 3116 only mention n=-1 as a default.

Skip

(*) A few days ago at work I saw someone check in a piece of code with

    f.read(-1)

That looked so strange to me I had to look up its meaning.  I don't think I
had ever seen someone explicitly call read with a -1 arg.

S


More information about the Python-3000 mailing list