Problem on Python/C++

clio wangye1 at
Sun Sep 30 17:26:01 CEST 2001

When I use the Python and C, I have this problem. How can I call Python 
function from C code.

What I am trying is to define a function pointer in C code and make a 
method in interface file ( I use SWIG) which sets the pointer to the 
function in Python.

--------------This is in interface file------------
//Grab a Python function as a Python object
%typemap(python,in) PyObject *pyfunc
	if (!PyCallable_Check($source))
		PyErr_SetString (PyExc_TypeError, "Need a callable object!");
		return NULL;
	$target = $source;

%inline %{
void set_pymethod(PyObject *pyfunc)
	Lkup_RPC_Svr=(void *)pyfunc;

The problem is when I compile, it return a error in set_pymethod that it 
can not convert the PyObject * to int (*())().

Thanks for any help!!


More information about the Python-list mailing list