Pep 3105: the end of print?

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Feb 16 09:50:40 EST 2007


On Fri, 16 Feb 2007 08:01:11 -0600, Edward K Ream wrote:

>> Why won't it be possible to make 'print' in Python 3 that supports all
>> the functionality of the current print statement, and then translate to
>> that ?
>> I saw an assertion to the effect that it wasn't possible - but no proof.
> 
> As discussed in the original post, the problem is the reverse:  the Python
> 2.x print statement does not support the keyword args required by the pep,
> so that print(foo) **in Python 2.x** can not simulate the effect of the
> print statement with a trailing comma.  Here is the theorum carefully stated
> and proved.
> 
> Theorem:  is not possible to define a function called print in Python 3.x
> such that
> 
> A) print (whatever) is syntaxtically valid in Python 2.x and
> 
> B) print(whatever) outputs what 'print whatever' outputs  in Python 2.x for
> all values of 'whatever'.

[snip]

> That's the proof.  Can you find a flaw in it?

No, but it doesn't matter. There's no particular reason why you have to
write "print (whatever)" in your code. What you need is *some function*
that is capable of duplicating the functionality of print, which can be
used under Python 2.x and 3. It isn't hard to write a function that will
duplicate print's functionality, so long as you give up the requirement
that it is called just like print.

The problem you describe with the print syntax only is a problem if you
insist on supporting Python 2.x and 3 from the same codebase. I don't
expect many people will try to do that. For those who do, don't use the
print syntax. As for the rest of us, we'll just continue to use print
using whichever syntax is appropriate.



-- 
Steven.




More information about the Python-list mailing list