On Thu, Oct 9, 2014 at 8:37 AM, Gregory Ewing
<greg.ew...@canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>
>>>>> operator.add is operator.__add__
>>
>> True
>
>
> That doesn't always seem to have been the case, however.
> In Python 2.7 and 3.3, I get
>
>>>> operator.add is operator.__add__
> False

Huh. So it is.

rosuav@sikorsky:~$ python3
Python 3.5.0a0 (default:301b9a58021c, Oct  2 2014, 09:20:24)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import operator
>>> operator.add, operator.__add__
(<built-in function add>, <built-in function add>)
>>>
rosuav@sikorsky:~$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import operator
>>> operator.add, operator.__add__
(<built-in function add>, <built-in function __add__>)
>>>

Presumably they have the same code behind them, just different
function names. But anyway, the fact that it doesn't throw back an
AttributeError proves that both functions do at least exist.

Learn something new every day!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to