Passing inner functions as arguments

Pablo Ripolles in-call at gmx.net
Thu Jun 20 20:28:03 EDT 2002


Hello all!

I am new to python, so sorry if i am asking the obvious. Here it
comes. Is there anything wrong with this code?

# Module to define math tools.
def momentum(f, k, a, b):
# Momentum of kth order of the given function f in [a, b].
    from Quadrature import quadrature
    def integrand(x):
    # Momentum's integrand in terms of the passed function f and k.
        return (f(x)) ** k
    return quadrature(integrand, a, b)

I am not sure if it is correct. It runs OK in Python 2.2.1 but not at
all in Jython 2.1 (java1.4.0). I am not sure about the scoping rules.
I there's something strange, please let me know!

Thanx in advance,
Pablo.



More information about the Python-list mailing list