I want to pass a formula inside a function parameter in Python, where the formula is a combination of other function parameters. In principle, it will look like this:
myfunction(x=2,y=2,z=1,formula="x+2*y/z") 6
or more general:
def myformula(x,y,z,formula): return formula(x,y,z)
This will allow the user to select any arithmetic expression in terms of x, y, and z without creating a new function.
One of the possibilities that I foresee is to convert a string to a line of code inside a function. Is anything possible in Python? Or any other ideas? Thanks
Simon source share