numeric expression from string?

Brian Blais bblais at bryant.edu
Sat Feb 4 06:48:11 EST 2006


Hello,

I have a string input from the user, and want to parse it to a number, and would like 
to know how to do it.  I would like to be able to accept arithmetic operations, like:

'5+5'
'(4+3)*2'
'5e3/10**3'

I thought of using eval, which will work, but could lead to bad security problems 
(not that it's a big  deal in my app, but still...)

string.atof won't do the job.  Is there a preferred way of doing this?


		thanks,


			Brian Blais


-- 
-----------------

             bblais at bryant.edu
             http://web.bryant.edu/~bblais



More information about the Python-list mailing list