Callback function call from C++

Gerhard Häring gerhard.haering at gmx.de
Fri Sep 13 17:54:52 CEST 2002


Sebastian Huber wrote in comp.lang.python:
> Hello,
> I want to install a Python callback function in a C++ extension module. 
> Everything works as desired, but is it possible to get the argument list 
> length and types of the function in advance. For example:
> 
> PyCallable_Check( o) != 0
> 	get the arglist and return 0 if not ok
> install the callback function
> 
> At the moment I get an error at the first call if the arglist is not ok, and I 
> want to avoid this.

I don't know if there's a C interface for this. If there isn't, you
can call the inspect module from your C++ app:

>>> def foo(x, y, *args, **kwargs): pass
...
>>> import inspect
>>> inspect.getargs(foo.func_code)
(['x', 'y'], 'args', 'kwargs')

HTH,

-- Gerhard



More information about the Python-list mailing list