Calling local functions from the C API
Martin v. Loewis
martin at v.loewis.de
Sat Nov 16 17:24:46 EST 2002
Jon Parise <jon at csh.rit.edu> writes:
> I'm familiar with calling functions using PyObject_CallObject().
> I generally use PyImport_ImportModule() to import a callable object
> from some module before executing it.
>
> However, I'm unclear as to how to go about getting a callable object
> from the current local scope (i.e. not from a named module).
>
> Help, please. =)
By "local scope", do you mean as in "local variable"? I.e. you do
def foo():
def bar()
pass
myext.somefunc()
and then you want the somefunc, which is implemented in C, to access
bar??? That isn't supported. It is possible, but you will have to read
the source yourself to find out how to do it.
Instead, I recommend that you do
myext.somefunc(bar)
instead, i.e. passing the callable as an argument to the extension.
Regards,
Martin
More information about the Python-list
mailing list