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

L

lg2779

Hello all
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
}
}

to call c method in the following python script:
class foo:
def __init__(self):
ReceivePythonPointer(self)
def Func(self):
print 'Func'
f1 foo

Is it impossible to get the pointer of C object when
ReceviePythonPointer is Called?
I want to get the pointer of "f1" object, Can you give me some advice ?

Best wishes.
 
F

Fredrik Lundh

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).

</F>
 
L

lg2779

Thanks for your answer.
I cant understand yet. The second parameter is "0" in the python'
documentation.
Can you give up a piece of code?
 
L

lg2779

Thanks for your answer.
I cant understand yet. The second parameter is "0" in the python'
documentation.
Can you give me a piece of code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top