[Python-Dev] Challenge about print >> None

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Tue, 12 Sep 2000 09:10:53 +0200


Vladimir wrote:
> I understand that you want me to think this way. But that's not my
> intuitive thinking. I would have written your example like this:
> 
> def func(file=sys.stdout):
>     print >> file, args
> 
> This is a clearer, compared to None which is not a file.

Sigh.  You code doesn't work.  Quoting the PEP, from the section
that discusses why passing None is the same thing as passing no
file at all:

    "Note: defaulting the file argument to sys.stdout at compile time
    is wrong, because it doesn't work right when the caller assigns to
    sys.stdout and then uses tables() without specifying the file."

I was sceptical at first, but the more I see of your counter-arguments,
the more I support Guido here.  As he pointed out, None usually means
"pretend I didn't pass this argument" in Python.  No difference here.

+1 on keeping print as it's implemented (None means default).
-1 on making None behave like a NullFile.

</F>