python 3's adoption

Alf P. Steinbach alfps at start.no
Wed Jan 27 18:29:25 CET 2010


* Daniel Fetchinson:
>>>>>>>>     * Print is now a function. Great, much improvement.
>>>>>> Actually not, IMHO. All it does is is to provide incompatibility.
>>>>> What incompatibility are you exactly talking about?
>>>>>
>>>>> Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57)
>>>>> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
>>>>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>>>> print( 'hello' )
>>>>> hello
>>>>>>>> print 'hello'
>>>>> hello
>>>>>
>>>>> Yes, this is with python 2.6.2 which is in the 2.x line of releases. So?
>>>> I gather that your example is about code that technically executes fine
>>>> with
>>>> both versions and produces the same result, i.e. that there is a subset
>>>> with
>>>> the
>>>> same syntax and semantics.
>>>>
>>>> But 'print' calls that technically execute fine with both versions may
>>>> and
>>>> will
>>>> in general produce different results.
>>>>
>>>> I.e. not just the syntax but also the semantics have changed:
>>>>
>>>>
>>>>  >>> import sys
>>>>  >>> sys.version
>>>> '2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]'
>>>>  >>>
>>>>  >>> print( "2+2 =", 2+2 )
>>>> ('2+2 =', 4)
>>>>  >>> _
>>>>
>>>>
>>>>  >>> import sys
>>>>  >>> sys.version
>>>> '3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)]'
>>>>  >>>
>>>>  >>> print( "2+2 =", 2+2 )
>>>> 2+2 = 4
>>>>  >>> _
>>> True. However, as someone else pointed out in a neighbouring thread you
>>> can do
>>>
>>> Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57)
>>> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>> from __future__ import print_function
>>>>>> print( "2+2 =", 2+2 )
>>> 2+2 = 4
>>>
>>> which gives 100% compatibility as far as print is concerned between 2.6
>>> and 3.x.
>> That makes the code behave with 3.x syntax and semantics regarding print.
>> I.e. it chooses one language.
>>
>> It doesn't make them compatible:
> 
> Of course it makes them compatible. I'm not saying any print-related
> code in python 2.6 is valid python 3 code, but that it is *possible*
> to write print-related code in python 2.6 that is also valid in python
> 3.
> 
>> if they were, then you wouldn't have to choose.
> 
> It seems to me you are arguing with the statement "Any print-related
> python 2.6 code is valid python 3 code". Nobody is making this
> statement. Let me repeat, what you should be arguing with is "It is
> possible to write print-related python 2.6 code that is also valid
> python 3 code". Perhaps I didn't make myself clear before, but at
> least now I hope it's clear what I mean.

Perhaps we're in violent agreement. :-)

However, the root node of this subthread was my statement about the needless 
incompatibility introduced by changing print in 3.x, whether that statement was 
correct or reasonable / whatever.

The main problem with the incompatibility is for porting code, not for writing 
code from scratch. It's also a problem wrt. learning the language. And I see no 
good reason for it: print can't really do more, or less, or more conveniently 
(rather, one has to write a bit more now for same effect).


Cheers,

- Alf



More information about the Python-list mailing list