Brian Blais schrieb: > 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?
No. If you already know about the pro and cons of eval, either go for it - or if it bothers you, write a parser using pyparsing and evaluate the expressions yourself. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list