Re: newbie: generate a function based on an expression

2005-12-14 Thread Jacob Rael
Thanks for all the suggestions and comments!! I will try all those suggestions just to I can figure out how they work. For phase 1 of this project, I will probably go with the eval. thanks again, happy hacking... jr -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: generate a function based on an expression

2005-12-13 Thread Jacob Rael
Overall I am trying to learn OOP by porting CppSim (http://www-mtl.mit.edu/~perrott) to Python. In CppSim, classes are defined that allow various functions to be defined, like amplifiers. In some cases they are linear: y = A*x some have offsets: y = A*x + off some are non-linear y = A*x -

Re: newbie: generate a function based on an expression

2005-12-13 Thread Jacob Rael
Another example is a filter. From the CppSim doc: Filter filt(1+1/(2*pi*fz)s,C3*s + C3/(2*pi*fp)*s^2,C3,fz,fp,Ts,1/gain,fz,fp,Ts); jr -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: generate a function based on an expression

2005-12-13 Thread Paul Rubin
Jacob Rael [EMAIL PROTECTED] writes: I read about the security concerns involved in using eval(). I don't expect this project to grow to the point where I require a web interface. However, since I am learning, I might as well learn the right way. I think you're going to have to write an

Re: newbie: generate a function based on an expression

2005-12-13 Thread Mike Meyer
Jacob Rael [EMAIL PROTECTED] writes: In CppSim, classes are defined that allow various functions to be defined, like amplifiers. In some cases they are linear: y = A*x some have offsets: y = A*x + off some are non-linear y = A*x - C*x**3 The coefficients and the function will remain

Re: newbie: generate a function based on an expression

2005-12-13 Thread Bengt Richter
On 12 Dec 2005 21:38:23 -0800, Jacob Rael [EMAIL PROTECTED] wrote: Hello, I would like write a function that I can pass an expression and a dictionary with values. The function would return a function that evaluates the expression on an input. For example: fun = genFun(A*x+off, {'A': 3.0,

Re: newbie: generate a function based on an expression

2005-12-13 Thread Michael Spencer
Bengt Richter wrote: On 12 Dec 2005 21:38:23 -0800, Jacob Rael [EMAIL PROTECTED] wrote: Hello, I would like write a function that I can pass an expression and a dictionary with values. The function would return a function that evaluates the expression on an input. For example: fun =

newbie: generate a function based on an expression

2005-12-12 Thread Jacob Rael
Hello, I would like write a function that I can pass an expression and a dictionary with values. The function would return a function that evaluates the expression on an input. For example: fun = genFun(A*x+off, {'A': 3.0, 'off': -0.5, 'Max': 2.0, 'Min': -2.0} ) fun(0) -0.5 fun(-10) -2

newbie: generate a function based on an expression

2005-12-12 Thread Ezequiel, Justin
def genFun(expr, locs): ... return lambda x: eval('min(Max,max(Min,%s))' % expr, locs, {'x': x}) ... fun = genFun(A*x+off, {'A': 3.0, 'off': -0.5, 'Max': 2.0, 'Min': -2.0} ) fun function lambda at 0x011B1470 fun(0) -0.5 fun(-10) -2.0 fun(10) 2.0 --

Re: newbie: generate a function based on an expression

2005-12-12 Thread Michael Spencer
Jacob Rael wrote: Hello, I would like write a function that I can pass an expression and a dictionary with values. The function would return a function that evaluates the expression on an input. For example: fun = genFun(A*x+off, {'A': 3.0, 'off': -0.5, 'Max': 2.0, 'Min': -2.0} )

Re: newbie: generate a function based on an expression

2005-12-12 Thread Mike Meyer
Jacob Rael [EMAIL PROTECTED] writes: Hello, I would like write a function that I can pass an expression and a dictionary with values. The function would return a function that evaluates the expression on an input. For example: fun = genFun(A*x+off, {'A': 3.0, 'off': -0.5, 'Max': 2.0, 'Min':