[Zope] Re: python script get defined function by name
Evan Simpson
evan@4-am.com
Tue, 15 Oct 2002 12:21:18 -0500
Lee Harr wrote:
> If I define a function inside a PythonScript, can I get that
> function by name somehow using getattr() or some other way?
>
> As in...
>
> #PythonScript
>
> def abc():
> pass
>
> abc = getattr(======, 'abc')
In Python, a 'def' statement binds the newly created function to a name
in the current namespace. Your definition acts a little bit like the
(totally imaginary) code:
abc = make_function('abc', (), 'pass')
...so 'abc' already exists, there's no need to "get" it.
Example:
def abc(x):
return x + 1
y = abc(1)
Cheers,
Evan @ 4-am