Language design

Neil Cerutti neilc at norwich.edu
Thu Sep 12 14:06:44 EDT 2013


On 2013-09-12, Markus Rother <python at markusrother.de> wrote:
> On 11.09.2013 23:15, Ethan Furman wrote:
>> On 09/11/2013 01:41 PM, Markus Rother wrote:
>>>      >>> () == []
>>>      False
>>>
>>>      But:
>>>
>>>      >>> bool(().__eq__([]))
>>>      True
>> 
>> This is not a trap, this is simply the wrong way to do it.  The magic
>> methods (aka dunder methods) are there for Python to call, not you
>> (except under special circumstances, such as when writing your own
>> dunder methods).
>
> While trying to do it, I learned that its not the right way to do it.
> However, I was not satisfied with the fact, that there is no built in
> pure function for operations on primitives.  Such that
>
>>>> def get_do_stuff (fn):
> ...     def do_stuff(x,y):
> ...         return fn(x,y)
> ...     return do_stuff
>
> I understand that python is not a functional language, but it
> frustrates me at times.

>>> import operator
>>> equal = get_do_stuff(operator.eq)(7, 7.0)
True

-- 
Neil Cerutti



More information about the Python-list mailing list