want to get the pointer of any python object in C++, but I Failed.

Fredrik Lundh fredrik at pythonware.com
Sun Dec 4 06:19:40 EST 2005

lg2779 at sina.com wrote:

>     I am trying to call the method of python object. But I dont know
> how to transfer the pointer of the python object into c++  .
> the C++ method to receive python object pointer :
> static PyObject*
> ReceivePythonPointer(PyObject* self, PyObject* args)
> {
>        PyObject* temp=NULL ;
>       //translate into C++ pointer, but Failed, the temp is null
>        if ( PyArg_ParseTuple(args, "0", &tmp) )
>        {
>                  //tmp
>        }
> }

use the letter O (for "object"), not the digit 0.

adding some error checking would also be a good idea. if PyArg_ParseTuple
returns false, Python's exception state is set.  you can use the PyErr_Print
function to print the exception traceback (this is very useful during debugging,
at least).


More information about the Python-list mailing list