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