calling a class method in a python module
Farshid Lashkari
lashkariNO at SPAMworldviz.com
Wed Feb 1 12:59:13 EST 2006
> Can anybody tell me how to call "f" in my C code?
Assuming you already have a handle to an instance of MyClass this should
do the trick:
PyObject *func = PyObject_GetAttrString(MyClassInst,"f");
if(func) {
PyObject *result = PyObject_CallObject(func,NULL);
if(result) {
//Do something with result
Py_DECREF(result);
}
Py_DECREF(func);
}
Have a look in the "Python/C API Reference Manual" for more information.
-Farshid
More information about the Python-list
mailing list