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
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 -
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
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
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
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,
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 =
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
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
--
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} )
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':
11 matches
Mail list logo