[Python-Dev] Replacement for print in Python 3.0

Barry Warsaw barry at python.org
Sat Sep 3 17:32:09 CEST 2005


On Sat, 2005-09-03 at 09:15, Paul Moore wrote:

> OK, how about a *single* builtin, named "print", which works something
> like Nick Coghlan's proposal (I'm happy to fiddle with the details,

So I've now read Nick's wiki page and here are my comments:

First, while I think you'll need two builtins, they won't be
distinguished by their end-of-line behavior.  That is easily handled by
a keyword argument.

More important IMO will be the need to distinguish whether you want a
format string or not.  The two use cases I came up with (and posted
about previously) are:

print 'obj:', obj, 'refcounts', sys.getrefcount(obj)
print 'obj: %s, refcounts: %s' % (obj, sys.getrefcount(obj))

Despite that these look superficially equivalent, they really aren't. 
The problem is that if you used one function, you'd have to make the
format string selectable by keyword argument.  But that's really ugly
because the focus of the operation /is/ the format string, and you
really want that to come first, not last, in the function call order. 
So the alternative is to do some magical interpretation of the first
argument to decide whether it's a format string or not.  Ick!

So I think it's best to have two builtins:

print(*args, **kws)
printf(fmt, *args, **kws)

I would also /require/ that any behavior changing keyword arguments
/not/ be magically inferred from the positional arguments.  So you'd
have to explicitly spell 'nl=False' or "stream=fp" if that's what you
wanted.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20050903/38d25d17/attachment.pgp


More information about the Python-Dev mailing list