__mul__ vs __rmul__ (and others) priority for different classes
dmitrey
dmitrey.kroshko at scipy.org
Fri Dec 11 13:48:38 EST 2009
hi all,
I have created a class MyClass and defined methods like __add__,
__mul__, __pow__, __radd__, __rmul__ etc.
Also, they are defined to work with numbers, Python lists and
numpy.arrays.
Both Python lists and numpy arrays have their own methods __add__,
__mul__, __pow__, __radd__, __rmul__ etc.
If I involve myPythonList * myClassInstance it returns just result of
my __rmul__; but when I invoke nuumpy_arr*myClassInstance it returns
another numpy array with elements [nuumpy_arr[0]*myClassInstance,
nuumpy_arr[1]*myClassInstance, ...].
Can I somehow prevent numpy array of using it __mul__ etc methods?
(and use only my __rmul__, __radd__, etc instead)?
Thank you in advance, D.
More information about the Python-list
mailing list