[Python-Dev] Challenge about print >> None

Greg Ward gward@mems-exchange.org
Thu, 14 Sep 2000 09:03:28 -0400

On 11 September 2000, Tim Peters said:
> > So as long as one uses extended print, she's already an advanced user.
> Nope!  "Now how did I get this to print to a file instead?" is one of the
> faqiest of newbie FAQs on c.l.py, and the answers they've been given in the
> past were sheer torture for them ("sys?  what's that?  rebind sys.stdout to
> a file-like object?  what?! etc").

But that's only an argument for "print >>file"; it doesn't support
"print >>None" == "print >>sys.stdout" == "print" at all.

The only possible rationale I can see for that equivalence is in a
function that wraps print; it lets you get away with this:

    def my_print (string, file=None):
        print >> file, string

instead of this:

    def my_print (string, file=None):
        if file is None: file = sys.stdout
        print >> file, string

...which is *not* sufficient justification for the tortured syntax *and*
bizarre semantics.  I can live with the tortured ">>" syntax, but
coupled with the bizarre "None == sys.stdout" semantics, this is too

Hmmm.  Reviewing my post, I think someone needs to decide what the
coding standard for ">>" is: "print >>file" or "print >> file"?  ;-)