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