[Python-Dev] Replacement for print in Python 3.0

Bill Janssen janssen at parc.com
Sun Sep 4 04:22:14 CEST 2005


Steven,

> Did you see Nick Coghlan's post?
>     http://mail.python.org/pipermail/python-dev/2005-September/056076.html
> I found his arguments to be reasonably compelling.

You were already convinced on Friday, so with you, he was preaching to
the choir.  I'm not surprised you found those "arguments" compelling.

I did not.

I thought it was rather weak.  The "points" he makes seem either
irrelevant or style judgements, and many seem mischaracterized by the
words used.

Point by point:

> "Print as statement" => printing sequences nicely is a pain
> "Print as function" => extended call syntax deals with sequences nicely

True, but I see it as a weakness in the Python string formatting
language, instead of a weakness with "print".  I think that print
should be extended with a printf-like format argument (or replaced
with a "printf" statement), and that the formatting available in this
format argument should handle this complaint.

> "Print as statement" => can't easily change the separator
> "Print as function" => keyword argument handles the separator nicely

So what?  To begin with, "print" users have been "changing the
separator" for years by doing string concatentation where it matters.
And there's always file.write() for those who need it.

> "Print as statement" => trailing comma suppresses newline by magic
> "Print as function" => keyword argument handles the line terminator nicely

This is a somewhat argumentative way of writing this.  It would be
better put as "newline emission control is performed syntactically",
which I see as neutral.  Style judgement.

> "Print as statement" => redirection is via a magic symbol
> "Print as function" => keyword argument handles redirection nicely

This is a somewhat argumentative way of writing this.  It would be
better put as "output redirection is indicated syntactically", which I
see as neutral.  Style judgement.  I might write this point as

  "Print as statement" => redirection is via a cool magic symbol
  "Print as function" => redirection done with a boring wordy keyword arg

See what I mean?

> "Print as statement" => can't easily save 'settings' for re-use
> "Print as function" => can use functional.partial to create custom version

So what?  Who in the world thought up this as a reasonable feature for
"print"?  Oh, well:  file a feature request and see what happens.

I think what Nick really is asking for is a better print statement --
and there's no particularly good reason to move to a function to
attain that end.  Let's add a good format specifier to "print",
instead.

Bill


More information about the Python-Dev mailing list