Using PyObject_CallObject on an Instantiated Class

J

John Smith

Greetings All,

I have something similiar to this:

Foo.py
class Foo(object):
def function(self):
pass

Bar.py
class Bar(Foo):
def function(self):
self.variable = self.variable + 1

Bleen.py
def GetBar():
package = __import__('Directory.Bar')
module = getattr(package, 'Bar')
classobj = getattr(module, 'Bar')
return classobj()

From C++, I call
PyObject* pBar = PyObject_CallMethod(pBleen, "GetBar"); // Not
exactly but close enough

Now, I'd like to save off some pointers to this instance of
Bar.function so that I can call it without the lookup overhead of the
PyObject_CallMethod (IE: using PyObject_CallObject)

However, Anything that I try to do fails.
From python, foo.__dict__ is empty, and foo.__class__.__dict__ refers
to the base class obviously. If I do the equivilant from C++ of:

PyObject* sClass = PyString_FromString("__class__");
PyObject* pClass = PyObject_GetAttr(m_pObject, sClass);
PyObject* sDict = PyString_FromString("__dict__");
m_pDictionary = PyObject_GetAttr(pClass, sDict);

Then m_pDictionary shows as empty in PyDict_Next() (Probably because
it is dictproxy)

So given that I'd have a few thousand Bars() each in it's own C++
class that would like to have a PyObject* to function() that would
contain it's own 'self.variable' how would I get the pointer to it so
that I could call PyObject_CallObject on it?

Thanks!
-John
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top