473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Using PyObject_CallObject on an Instantiated Class

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
Jul 18 '05 #1
0 2784

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: 胡岳偉(Yueh-Wei Hu) | last post by:
Hi all, I have 2 questions about template function as friends in template classes. I don't know why, and hope someone could help me. ...
0
by: Yueh-Wei Hu | last post by:
Victor Bazarov <v.Abazarov@comAcast.net> wrote in message news: ============================================================== > > Question 1: > >...
8
by: Dev | last post by:
Hello, Why an Abstract Base Class cannot be instantiated ? Does anybody know of the object construction internals ? What is the missing information that prevents the construction ? TIA....
16
by: Islam Elkhayat | last post by:
In my web application i use satalite assembly to localize my web form.. Instead of set the each control text to the resourcemanager getstring() method i try to use foreach loop private string...
2
by: yinglcs | last post by:
I have the following code, which use template as the parent class of my other class. But I have "instantiated from here" compile error at this line: class C: public B2<A>. Can some one...
8
by: pirho | last post by:
Not sure if I'm posting this in the right spot, but.... Lets say i have a class for data access that gets instantiated on each page in a web application ( .Net 1.1 ) From inside that class,...
1
by: Sami Vaisanen | last post by:
Hello group, I'm trying to get the Python exception information (message and traceback) stored into a string in my C++ code. However all i get back is the string "None". All the checks pass and...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
22
by: phil.pellouchoud | last post by:
I did some searching online and i couldn't find anything in reference to this. I am using MinGW, gcc 4.3 and am having the following compilation issue: class CFoo { public: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.