Hi all,
This time a question: is there a preferred way of getting a complete
list of symbols reserved by SymPy, i.e. atoms which have a default
meaning (E, pi, EulerGamma, oo, etc.)?
By experimenting and reading the source, I found out that in the old
0.6.x this can be done with
import sympy as sy
L = sy.Basic.singleton.keys()
and in the more recent 0.7.x with
import re
import sympy as sy
L = filter( lambda name: re.match("__", name) is None, dir(sy.S) )
L = map( lambda name: str(eval("sy.S.%s" % name)), L )
The reason I'm asking is of course that the internals may change in
later versions, so an API-stable way to do this would be preferable.
The (current) use case is custom validation for user input that is going
to be sympified. It is foreseeable this could also be used in GUI
applications to build a list of default constants.
My aim here is to avoid unpleasant surprises in user-defined quantities
in the FEM project; e.g. if the user happened to pick the symbol E for
(say) a Young modulus, SymPy would interpret that as exp(1) in any
expression that was sympified. This in turn could confuse the expression
processing. Currently I use the above code to fetch the reserved names,
but is there a better way to get them?
And finally, a related question: is there a way to get a human-readable
description for a reserved name (e.g. "zoo" -> "complex infinity")? I
didn't find anything in the API for this.
-J
--
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.