Am 18.05.2015 um 15:56 schrieb Carsten Knoll:
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'
That happens because we use __slots__ for performance reasons.
However, storing attributes in that way is a bad idea in general,
because you risk name conflicts with future versions of SymPy. (That's
also the reason why using subclasses to extend a library tends to break
over time.)
Alternative 1: You could set up a dict with a Symbol-to-attributes
mapping: Symbols are hashable (that's a guaranteed property).
Alternative 2: We could add a `userdict` attribute in Symbol, so that
SymPy users can store additional attributes there.
I'm not too happy with either alternative.
Maybe we can give you better help if you describe your use case in some
more detail.
Regards,
Jo
--
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/555A2182.8070309%40durchholz.org.
For more options, visit https://groups.google.com/d/optout.