Elegant solution needed: Data manipulation

Steven Majewski sdm7g at Virginia.EDU
Wed Jan 30 20:00:19 EST 2002


On 30 Jan 2002, Mark wrote:

> I also have an equation:
> add( speed , mul (weight, height) )
>
> These both live in their own files.

If you could write the rules instead as:

	(add speed (mul weight height))

it would be lisp and you wouldn't even have to parse it.


But if you want to do it with python, just import operator:

>>> from operator import *
>>> add( 1, mul( 2,3 ))
7

If you can arrange to get your variables assinged first,
your formula will be directly executable:

>>> speed = 10
>>> weight = 100
>>> height = 20
>>> input( 'formula: ' )
formula: add( speed , mul (weight, height) )
2010

-- Steve Majewski






More information about the Python-list mailing list