[Python-Dev] Challenge about print >> None

Skip Montanaro skip@mojam.com (Skip Montanaro)
Wed, 13 Sep 2000 12:48:10 -0500 (CDT)


    David> Thus, FWIW, I'm -1 on the >>None construct.  I'll have a hard
    David> time teaching it, and I'll recommend against using it (unless and
    David> until convinced otherwise, of course).

I've only been following this thread with a few spare neurons.  Even so, I
really don't understand what all the fuss is about.  From the discussions
I've read on this subject, I'm confident the string "print >>None" will
never appear in an actual program.  Instead, it will be used the way Guido
envisioned:

    def write(arg, file=None):
	print >>file, arg

It will never be used in interactive sessions.  You'd just type "print arg"
or "print >>file, arg".  Programmers will never use the name "None" when
putting prints in their code.  They will write "print >>file" where file can
happen to take on the value None.  I doubt new users will even notice it, so
don't bother mentioning it when teaching about the print statement.

I'm sure David teaches people how to use classes without ever mentioning
that they can fiddle a class's __bases__ attribute.  That feature seems much
more subtle and a whole lot more dangerous than "print >> None", yet I hear
no complaints about it.

The __bases__ example occurred to me because I had occasion to use it for
the first time a few days ago.  I don't even know how long the language has
supported it (obviously at least since 1.5.2).  Worked like a charm.
Without it, I would have been stuck making a bunch of subclasses of
cgi.FormContentDict, all because I wanted each of the subclasses I used to
have a __delitem__ method.  What was an "Aha!" followed by about thirty
seconds of typing would have been a whole mess of fiddling without
modifiable __bases__ attributes.  Would I expect the readers of this list to
understand what I did?  In a flash.  Would I mention it to brand new Python
programmers?  Highly unlikely.

It's great to make sure Python is approachable for new users.  I believe we
need to also continue improve Python's power for more advanced users.  That
doesn't mean turning it into Perl, but it does occasionally mean adding
features to the language that new users won't need in their first class
assignment.

+1 from me.  If Guido likes it, that's cool.

Skip