Accessing class members from C

D

disgracelands

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
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

disgracelands said:
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
 
D

disgracelands

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 said:
disgracelands said:
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
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top