As you find, sympify converts strings to SymPy expressions.
To answer another question, character names can be anything, but sympify will only parse valid Python identifiers for character names. But you can do
>>> Symbol('{myvar-42}') + 1 {myvar-42} + 1
And note that valid Python identifiers should not be single letters. They can be any combination of letters, numbers, and underscores that do not start with a number, such as x_2 or abc123 .
If you still need to parse strings but want invalid Python identifiers to be character names, perhaps the purest way would be to use regular names and substitute them for others, for example
>>> expr = sympify('x + 1') >>> expr.subs(Symbol('x'), Symbol('{myvar-42}') {myvar-42} + 1
Finally, to replace characters with letters, you can use the locals argument for sympify as you did, or if you want to replace them later, use subs:
>>> x, y, z = symbols('xy z') >>> expr = sympify('x/z - y') >>> expr.subs({x: 10, y: 5}) 10/z - 5
source share