[Python-Dev] Challenge about print >> None

Guido van Rossum guido@beopen.com
Mon, 11 Sep 2000 18:14:38 -0500

> Seems like people are very surprised to see "print >> None" defaulting
> to "print >> sys.stderr". I must confess that now that I'm looking at
> it and after reading the PEP, this change lacks some argumentation.
> In Python, this form surely looks & feels like the Unix cat /dev/null,
> that is, since None doesn't have a 'write' method, the print statement
> is expected to either raise an exception or be specialized for None to mean
> "the print statement has no effect". The deliberate choice of sys.stderr
> is not obvious.
> I understand that Guido wanted to say "print >> None, args == print args"
> and simplify the script logic, but using None in this case seems like a
> bad spelling <wink>.
> I have certainly carefully avoided any debates on the issue as I don't
> see myself using this feature any time soon, but when I see on c.l.py
> reactions of surprise on weakly argumented/documented features and I
> kind of feel the same way, I'd better ask for more arguments here myself.

(I read the followup and forgive you sys.stderr; didn't want to follow
up to the rest of the thread because it doesn't add much.)

After reading the little bit of discussion here, I still think
defaulting None to sys.stdout is a good idea.

Don't think of it as

  print >>None, args

Think of it as

  def func(file=None):
    print >>file, args

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)