[Python-Dev] Hacking print (was: Replacement for print in Python 3.0)

Bill Janssen janssen at parc.com
Sun Sep 4 00:32:38 CEST 2005


Just to add a bit more perspective (though I continue to believe that
"print" should be retained as-is):

In my UpLib code, I no longer use print.  Instead, I typically use a
variant of logging called "note" instead of print:

  note ([LEVEL, ] FORMAT-STRING [, *ARGS])

It works just like C printf, but uses the Python string formatting to
merge the ARGS into the FORMAT-STRING.  Having the printf-style
formatting seems to me to outweigh the irritation of having to
surround my args with parentheses (why are parentheses shifted
characters?!), though having both would be great.  If an integer LEVEL
is provided, it is compared to the current output-level setting, and
if LEVEL is *higher* than the current setting, the output is
suppressed.  The default LEVEL is 1.  Normally, "note" writes to
sys.stderr, but there are functions to set both the note-level and the
note-sink.

Adding the "\n" to the end of the format string seems to be just as
easy as writing "noteln", and much clearer, so I've never even
considered adding a "-ln" variant of this function.  I think the "-ln"
variants made familiar by Pascal and Java were a bad idea, on a par
with the notion of a split between "text" and "binary" file opens.

I might even be in favor of retiring "print" if it were replaced with
a different statement, say "printf", which had the capabilities of
"note", but didn't require parentheses around its arguments.

Bill


More information about the Python-Dev mailing list