Evaluating the contents of a string

Matt Barnett mbarnett at ualberta.ca
Mon Mar 19 13:49:14 EST 2001


----------
In article <snitl5r6oy.fsf at motorola.com>, Aaron Ginn 
<aaron.ginn at motorola.com> wrote:


>
> Is there a simple way to evaluate the contents of a string assuming
> that string contains only nunbers and mathematical operators?
>
> For example, I'm parsing a file that contains expressions contained in
> parantheses such the following:
>
> 12 net64 a vss vss n w=1.1u l=0.5u ad=(1.1 * 1.15) as=(1.1 * 1.15)
>                                       ^^^^^^^^^^^^    ^^^^^^^^^^^^

eval("1.1 * 1.15")

>When the first closing
>parenthesis is found in the example above, the string to be evaluated
>will be '1.1 * 1.15'.  Is there a module that will mathematically
>evaluate this string?

Yup



More information about the Python-list mailing list