det*_*tly 41 c python python-embedding python-c-api python-extensions
假设我的对象布局定义为:
typedef struct {
PyObject_HEAD
// Other stuff...
} pyfoo;
Run Code Online (Sandbox Code Playgroud)
...和我的类型定义:
static PyTypeObject pyfoo_T = {
PyObject_HEAD_INIT(NULL)
// ...
pyfoo_new,
};
Run Code Online (Sandbox Code Playgroud)
如何pyfoo
在C扩展中的某个位置创建新实例?
Fré*_*idi 45
调用PyObject_New(),然后调用PyObject_Init ().
编辑:最好的方法是调用类对象,就像在Python本身一样:
/* Pass two arguments, a string and an int. */
PyObject *argList = Py_BuildValue("si", "hello", 42);
/* Call the class object. */
PyObject *obj = PyObject_CallObject((PyObject *) &pyfoo_T, argList);
/* Release the argument list. */
Py_DECREF(argList);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12140 次 |
最近记录: |