Le vendredi 09 mars 2012 à 20:36 -0500, Alan Bromborsky a écrit : > What worked for me is:
No, I don't think that does what you want. > class Vector(Symbol): > > def __init__(self,basis_str=None): > if isinstance(basis_str,Vector): > self = basis_str This binds basis_str to the *local name* 'self', which has no effect whatsoever on anything that happens outside this __init__() method (and since you don't do anything else with self, the statement has no effect at all). > else: > if basis_str == None or basis_str == '0': > self = S(0) ditto > else: > Symbol.__init__(self,basis_str,commutative=False) Symbol doesn't define __init__. This actually calls object.__init__() which does nothing. > self.is_commutative = False > > > but I don't know why I should have to do it! What you should do is implement __new__, and call Symbol.__new__. As a rule, sympy objects only use __new__, not __init__. Remember that in Python, __init__ is for setting up the state of an existing object, while __new__ creates the object in the first place. So if you want a constructor call like "Vector(...)" to return objects of different types, you have to implement that in __new__. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.