more python to c/c++ questions.

Jr. King n at n.com
Mon Jun 7 12:01:17 EDT 1999


Can you pass a user defined type in python to a c/c++ program.  I didn't see
this in the docs and I would assume it isn't possible.  I have the questions
commented inside my code

I snipped (=-)) this from my code...

pythond.py
class Cow:
 i = 10
 x = 0
 str = "string"

testmeth.setCallback(setN)  //fine
testmeth.testmeth(13,9)  //fine
cow = Cow()  //fine
testmeth.objpass(cow);   //problem with this and the c code.

code.cpp
static PyObject* objPass(PyObject *self, PyObject* args){
    PyObject *result = NULL;
    PyObject *temp;

    if (PyArg_ParseTuple(args, "O", &temp)) {  /*this works ok*/
                                            /*But how Am I supposed to
parseTuple the arg???*/
        }
        Py_INCREF(Py_None);
        result = Py_None;
    }
    return result;
}


Do I need to make a C++ class or struct that can map directly to the python
object ?

Thanx






More information about the Python-list mailing list