Implementing/Overriding operators
Posted: Fri May 27, 2016 1:46 am
Hello,
I've got a project where I am implementing/overriding operators for a class. Consider this entered at a CPython prompt:
The same code on a Pyboard yields:
I'm on MicroPython v1.8-76-gca63c77 on 2016-05-15; PYBv1.0 with STM32F405RG
Any ideas? I think I've got problems with other operator overloads as well. I can do what I need with regular methods on my objects but I thought it would be nice to implement operators for my base class which is really just a wrapper around numbers.
Thanks!
/Daryl
Please don't forget to put the code in the appropriate bbcode - platforma
I've got a project where I am implementing/overriding operators for a class. Consider this entered at a CPython prompt:
Code: Select all
>>> class Monkey:
... def __abs__(self):
... return "Fred"
...
>>> m = Monkey()
>>> abs(m)
'Fred'
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert Monkey to int
Any ideas? I think I've got problems with other operator overloads as well. I can do what I need with regular methods on my objects but I thought it would be nice to implement operators for my base class which is really just a wrapper around numbers.
Thanks!
/Daryl
Please don't forget to put the code in the appropriate bbcode - platforma