Hi!
I'm trying to use a matrix implementation written in python, but it does not work; it seems that __mul__() and __div__() are not implemented.
Can someone confirm?
__mul__(), __div__()...
__mul__(), __div__()...
Frédéric
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: __mul__(), __div__()...
Firstly __div__() isn't in Python 3.4 because of the changes made to the meaning of the division operator. See
https://docs.python.org/3.4/library/operator.html
However it does seem that __mul__ and __truediv__ aren't implemented, although __add__ and __sub__ are. I suggest you flag it up on github and hopefully these operators will be added. I tested with this class which works as expected in cPython, but multiplication and division fail in Micropython.
In Micropython:
Regards, Pete
https://docs.python.org/3.4/library/operator.html
However it does seem that __mul__ and __truediv__ aren't implemented, although __add__ and __sub__ are. I suggest you flag it up on github and hopefully these operators will be added. I tested with this class which works as expected in cPython, but multiplication and division fail in Micropython.
Code: Select all
class foo(object):
def __init__(self, val):
self.bar = val
def __mul__(self, other):
return self.bar * other.bar *2
def __truediv__(self, other):
return (self.bar /other.bar) *2
def __add__(self, other):
return (self.bar + other.bar) *2
def __sub__(self, other):
return (self.bar - other.bar) *2
Code: Select all
>>> a = test4.foo(9.0)
>>> b = test4.foo(4.0)
>>> a+b
26
>>> a*b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand types for binary operator: 'foo', 'foo'
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.