On Mon, May 18, 2015 at 11:56 PM, Carsten Knoll <[email protected]> wrote:
> I want to equip an Symbol with an additional attribute to store some
> specific information right in place.
>
> For 'normal' Python classes it is no problem to dynamically create an
> additional attribute for an already existing instance.
>
> However, for sympy Symbols if I try
>
> x = Symbol('x')
> x.k = 0
>
> I get the error
>
> AttributeError: 'Symbol' object has no attribute 'k'
>
> Is there any possibility to equip the Symbol x with this attribute?
>
> I already tried this workarround:
>
> class ExtendedSymbol(sp.Symbol):
>     pass
>
>
> x = ExtendendSymbol('x')
>
> x.k = 0 # no problem here
>
>
> However then I have the following unwanted behavior:
>
> x2 = sp.Symbol('x')
> x2 == x # -> False

Not sure if it is possible for your situation, but may be you could
overrride the __eq__ method in your ExtendedSymbol class to call the
base class's method?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CANODV3%3DMF_Gs_tZLcqTQuaALAQkC%3DiYsi-H9BUkWweSY85Oz%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to