Evaluating the contents of a string

Aaron Ginn aaron.ginn at motorola.com
Mon Mar 19 18:48:13 CET 2001

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)
                                      ^^^^^^^^^^^^    ^^^^^^^^^^^^

I'm using a stack to determine when an expression can be evaluated
(i.e., when a closing paranthesis is found), and I'm storing the
contents of the parantheses in a string.  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?


Aaron J. Ginn                    Phone: 480-814-4463
Motorola SemiCustom Solutions    Pager: 877-586-2318
1300 N. Alma School Rd.          Fax  : 480-814-4463
Chandler, AZ 85226 M/D CH260     mailto:aaron.ginn at motorola.com

More information about the Python-list mailing list