*sympify("x")* --> always returns a *Symbol("x")* not an *Expr *
*sympify("x**1")--> *work fine because it become a proper expression (
pow object).
*parse_expr("x") -->* is more flexible, and with (local_dict) or
transformation you can treat "x" as an expression.
here is the solution: use *parse_expr* instead of *sympify*.
from sympy import Symbol
from sympy.parsing.sympy_parser import parse_expr
x = Symbol("x")
expr = parse_expr("x", local_dict={"x": x})
print(expr) # outputs: x
On Tuesday, January 6, 2026 at 5:04:33 PM UTC+5:30 [email protected]
wrote:
> Would like some advice on use of string "x" as expression source.
> "x**1" can work ok with sympify
> "1x" can work with parse_expr
>
> We try "x" with sympify and can see it return a type that is not sympy.Expr
> Apparently "x" can never work by design <- will that change?,
> is some option combo to parse "x"?
>
> thanks for any comments
> Daniel.
>
--
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 view this discussion visit
https://groups.google.com/d/msgid/sympy/364a32a5-b4b0-4b27-b6db-c5429f823d83n%40googlegroups.com.