Hi,
I am trying to create a class that is basically the sum of two arguments
given in the constructor. Here is what I have done (simplified example with
omitted arguments and slots):
class BeamParameter(Add):
__slots__ = ['x', 'y']
def __new__(cls, x, y):
obj = Add.__new__(cls, x, I*y)
obj.x = x
obj.y = y
return obj
It works ok when Add returns Add:
>>>q=BeamParameter(1,1)
>>>q
1+I*1
But it fails when Add returns Mul:
>>>q=BeamParameter(0,1)
---> 54 obj.x = x
AttributeError: 'Mul' object has no attribute 'x'
The __slots__ are lost somewhere for some reason. I'm afraid that I don't
understand why. Maybe I should not use Add as a superclass. Do you have any
solutions?
Stefan
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.