473,503 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing class members from C

I'm starting to develop an application in Python running the interpreter
from C, i've got callbacks and stuff setup (was pretty pleased with that)
and i'm starting to get my head around the reference counting but i've hit a
snag. I'm creating objects within python then linking them to their C
counterparts, what i want to do now is directly access the python class
variable objects from C. Basically i have the python class object as a C
pointer and i want to access one of the class members, somevar, and even
read access would be fine. I'm guessing theres a really easy way to do this
but i can't find an example in any of the docs and google turns up pages of
unrelated problems.

I know that i could write Get() and Set() methods for each member variable
but it doesn't seem like a very nice solution.

Cheers for any help

Jul 18 '05 #1
2 1956
disgracelands wrote:
Basically i have the python class object as a C
pointer
You mean, you have an instance object?
and i want to access one of the class members, somevar,


And you want to access an instance attribute?

I recommend to use PyObject_[Get|Set]Attr[String] (this would
actually work for class objects and class members as well).

Regards,
Martin

Jul 18 '05 #2
Ah! Thats exactly what i was after, that just saved me a whole bunch of
time and probably helped keep my blood presure within safe limits too.

Cheers for the help,
dis

"Martin v. Löwis" <ma****@v.loewis.de> wrote in message
news:bi*************@news.t-online.com...
disgracelands wrote:
Basically i have the python class object as a C
pointer


You mean, you have an instance object?
and i want to access one of the class members, somevar,


And you want to access an instance attribute?

I recommend to use PyObject_[Get|Set]Attr[String] (this would
actually work for class objects and class members as well).

Regards,
Martin

Jul 18 '05 #3

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

Similar topics

2
4192
by: JM | last post by:
Hello everyone, Does anybody know about, have documentation on, or have any code samples on how to access class members from a python class in C++. Say I have a simple python script: ...
5
3632
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
5
2394
by: Sandeep | last post by:
Hi, In the following code, I wonder how a private member of the class is being accessed. The code compiles well in Visual Studio 6.0. class Sample { private: int x; public:
2
2268
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point...
6
2592
by: harry | last post by:
Hi ppl I have a question about memory layout of a class. Consider the code below: class Base1 { virtual void f() { cout << "Base1::f" << endl; } virtual void g() { cout << "Base1::g" <<...
9
3670
by: Joel Moore | last post by:
I'm a little confused here. If I have the following: Public ClassA Friend varA As Integer Private varB As Integer Private ClassB Public Sub MethodA() ' How can I access varA and varB here?...
4
1410
by: John | last post by:
I am having a problem accessing the members in a structure via an interface and Class. ***Development Code*** Structure Person Public Name as String End Structure Interface IData Public...
3
4590
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
6
5016
by: earthwormgaz | last post by:
Is the following legal? class Outer { class Inner { private: Inner() { } };
6
8132
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.