numeric expression from string?
Claudio Grondi
claudio.grondi at freenet.de
Sat Feb 4 09:57:43 EST 2006
Brian Blais wrote:
> 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
>
>
I have no idea if it is the right thing for what you need, so it would
be nice to get response if it is or not:
http://www.strout.net/python/pythonica.html
Claudio
More information about the Python-list
mailing list