Python: Eval with undefined variables (2*x+x = 3*x) -


i'm looking way, calculate strings, might include variables. eval won't job, want use undefined variables. i'm talking function, turn "2*3*x" "6*x" example.

is there function that?

you use sympy symbolic computation:

in [126]: import sympy sy  in [127]: sy.simplify('2*x+x') out[127]: 3*x 

to convert rationals floats, use sy.nfloat:

in [170]: sy.nfloat(sy.simplify('2*3+x+3/4')) out[170]: x + 6.75 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -