regex - Replace string value in regular expression with integer value in python -


this question has answer here:

in python code, user enters mathematical expression. want replace variables integer values , calculate result. can user regular expression in python replace variables integer values cant calculate sum replaced string of type string. can in tcl. has built in expr command pass string , automatically converts mathematical expression , calculates result. there way same in python?

thank you

yes there eval. example:

a=3 b=4 s="(a*a+b*b)**.5" eval(s) 

but warned maybe security risk. may better use sympy http://sympy.org/en/index.html


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -