PEP 0214 - extended print statement

Thomas Wouters thomas at xs4all.net
Wed Aug 23 05:54:32 EDT 2000


On Wed, Aug 23, 2000 at 05:43:51PM +1000, Richard Jones wrote:

> Given that print has almost-function-like arguments (it looks like it
> takes a tuple of arguments, just like a function, except without the
> brackets) ... why not go for something a little more extensible and
> intuitively consistent ...

But print *isn't* a function. In fact, the fact that it almost looks like
one is very deceiving, and should be fixed! :) 'print' attaches a special
meaning to a trailing comma, something a function cannot do. Worse, a
trailing comma in a argument list is accepted (because it's basically just a
tuple) but not passed to the function itself! How inconsistent can you get
:)

'intuitively consistent' is very subjective. It's true that Python tries to
keep everything in a general theme, and is suprisingly good at it, too.
(Like using tuples for function argument lists, the trailing comma, being
able to do tuple-unpacking in them, etc.) But 'print' is already
non-compliant<wink> with functioncalls, and conforming it would mean losing
functionality. At least now it's even more obviously not a function call.

Seriously, Guido has good ideas on *how* Python should be consistent, and
he's good in spreading those ideas as well.

> >>> print foo, bar, baz, file=logfile
> .. you could then ...
> >>> print foo, bar, baz, file=logfile, sep=':'

If you want that behaviour, you're better off making it a function call:

pr(foo, bar, baz, file=logfile, sep=':', nl=0)

(where the 'nl=0' argument replaces the trailing comma in print statements)

You don't have to write the new Python constructs, as long as you are able
to read them. And is "print >> file, some, argu, ments" really that hard to
parse or understand ? I don't think so. I know one thing: this feature is
going to make Mailman a lot easier to read. Pity it'll be a while before
Mailman can use it, because I'm sure Barry wants to keep Mailman compatible
with 1.5.2 at least as long as he kept it compatible with 1.5 (.0, not
.1/.2) ;-P

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list