2

我有我用 C 编写的 Python 扩展。目前,我需要在某个外部纯 Python 模块中声明的类型的扩展对象的函数中进行处理(比如说,它的名称是ext_module)。首先,我需要确保输入对象类型对应于ext_module. 我该如何实施?一些额外的代码:

static PyObject * extensionFunction( PyObject* self, PyObject *args ) {
    const char *inputString = NULL;
    PyObject *inputList = NULL;

    if ( 0 == PyArg_ParseTuple( args, "sO", &inputString, &inputList ) ) {
        return NULL;
    }

    if ( 0 != PyList_Check( inputList ) ) {
    // here I need to check whether the list items are instances of ext_module.ExtClass
    } else {
        PyErr_SetString( PyExc_TypeError, "extensionFunction: expected list" );
        return NULL;
    }
    // process arguments

    Py_RETURN_NONE;
}

实际上我可以尝试调用预期的方法并得到一个异常NotImplementedError,但我不确定这是否是正确的方法。

4

0 回答 0