Passing inner functions as arguments
Fernando Pérez
fperez528 at yahoo.com
Thu Jun 20 20:36:50 EDT 2002
Pablo Ripolles wrote:
> 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!
Nested scopes are not on by default in 2.1 You need AT THE TOP of your file to
put 'from __future__ import nested_scopes'.
Cheers,
f.
ps. De paso, en inglés se usa 'moment/moments' para describir los momentos de
una función/distribución. 'momentum/momenta' es la palabra cuyo significado
es el momento mecánico (masa*velocidad en su descripción más simple, o
derivada de la Lagrangiana en general). El problema es que en español usamos
'momento' para ambas cosas :)
More information about the Python-list
mailing list