Problem Calling Python callbacks from C

Michael Hudson mwh at python.net
Tue Apr 2 14:17:09 EST 2002


Tim Egbert <tegbert at abl.med.utah.edu> writes:

> I'm able to call a Python callback _function_ from C code by following the      
> information in "Extending and Embedding the Python Interpreter," section
> 1.6, but I can't get the callback to work if I'm calling a Python object
> _method_.  Does anyone know how to do that?
> 
> In other words, it works if I'm using a Python function such as:
>    
>     def callback_func(i):
>         print i
> 
> and I set "callback_func" as the callback but not if the callback is an
> object method such as:
> 
>     class callbackClass:
>         def callback_method(self,i):
>             print i
>     cbc=callbackClass()
> 
> and I set the callback as "cbc.callback_method".
> 
> I'm using the "PyEval_CallObject(callback,arglist)" function in my C code
> to make the callback.

That ought to work.

> I assume the problem has to do with not having the "self" argument
> available in the arglist for the callback method, but I haven't been
> able to find any documentation on how to provide "self" or what
> Python function to use for calling an object method.

Well, I'm afraid I haven't bought my telepathy upgrade for 2002, so
you'd better

a) post some more code
b) tell us exactly what goes wrong

Cheers,
M.



More information about the Python-list mailing list