How Would You Do: Parsing and Expression Evaluation

Larry Bates lbates at swamisoft.com
Tue Apr 27 10:16:13 EDT 2004


I may not be understanding what you want to do but
here goes:

You might just want to use eval() function and have
the expression evaluated by Python.  That way your
expression could be any Python expression and you
don't have to parse the expression at all (e.g eval
parses and executes it and returns the value).  You
also don't have to "translate" the formulas.  They
are already Python expressions.  Python expression
syntax is pretty much like what you would want.

Larry Bates
Syscon, Inc.

"Al Christians" <achrist at easystreet.com> wrote in message
news:108rren1js1hn71 at corp.supernews.com...
> I've got an idea for an application, and I wonder how much of what it
> takes to create it is available in open source python components.
>
> My plan is this -- I want to do a simple spreadsheet-like application:
> I've used a wxGrid, so I expect that wxPython will do fine for the user
> interface.   The spreadsheet can be organized vertically, one item per
> line.  It might need no more than 100 rows or so.  On each line, the
> user will enter in one column an item (variable) name and, in another
> column, a formula or  expression for computing the item's value.  A
> third column will show the computed value.   There will usually be some
> circular references between the items, but their values will converge
> quickly with repeated evaluation.
>
> The final feature is a button that the user can click when they have the
> sheet set up correctly -- it will translate the formulas into simple C
> and python code to perform the same calculations as the spreadsheet.
>
> The formulas should be pretty easy -- add, subtract, multiply, divide,
> log, exponential,  and perhaps some user-defined functions.
>
> Are there any off-the-shelf python libraries that would make this kind
> of app much easier?  I don't have any special experience related to such
> things, so I surely don't want to re-invent the wheel out of pure
> ignorance -- should I try the parsing tools in the standard python
> library, or will something else work better for me?
>
> TIA for any advice,
>
>
> Al





More information about the Python-list mailing list