[Python-Dev] Replacement for print in Python 3.0

Nick Coghlan ncoghlan at gmail.com
Sun Sep 4 04:43:48 CEST 2005

Bill Janssen wrote:
> 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.

I agree with this point actually. There should be an "iterable" formatting 
code that looks something like "%[sep]i"

Then "%i" % (my_seq,) would be the equivalent of "".join(my_seq), only 
allowing it to be easily embedded inside a larger format string.

Some other examples:
("% i" % my_seq)  => " ".join(my_seq)
("%, i" % my_seq) => ", ".join(my_seq)

I see this as being similar to the way that "%.2f" controls the way that a 
floating point value is displayed.

> 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.

The real driver is that Guido wants to change it, but I'm actually starting to 
think I like having the print statement, and what I really want is a 'format' 
builtin to get around the tuple-related quirks of the string mod operator, and 
an enhancement to the string mod operator to deal better with iterables.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list