[Python-Dev] Why not support user defined operator overloading ? (original) (raw)
张佩佩 zhangpeipei812 at outlook.com
Mon Sep 30 02:23:12 CEST 2013
- Previous message: [Python-Dev] Why not support user defined operator overloading ?
- Next message: [Python-Dev] Why not support user defined operator overloading ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello: I agree with Steven D'Aprano. Here is an example:
class A(object): def init(self, value): self.value = value def add(self, other): return self.value + other.value magic_method = {'+':add}
a1 = A(1) a2 = A(2)
We only need a macro expand a1 + a2 to a1.magic__method['+'](a, b)
the later can be execute on Python.
Regards peipei
- Previous message: [Python-Dev] Why not support user defined operator overloading ?
- Next message: [Python-Dev] Why not support user defined operator overloading ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]