On 09/12/2013 10:51 AM, Markus Rother 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
--> operator.__all__  # public api methods are in __all__
['abs', 'add', 'and_', 'attrgetter', 'concat', 'contains', 'countOf', 'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand', 'iconcat', 'ifloordiv', 'ilshift', 'imod', 'imul', 'index', 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift', 'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le', 'length_hint', 'lshift', 'lt', 'methodcaller', 'mod', 'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift', 'setitem', 'sub', 'truediv', 'truth', 'xor']

Imports are a Good Thing; not everything has to be built in.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to