Connecting Tech Pros Worldwide Forums | Help | Site Map

Accessing class members from C

disgracelands
Guest
 
Posts: n/a
#1: Jul 18 '05
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




Martin v. Löwis
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Accessing class members from C


disgracelands wrote:
[color=blue]
> Basically i have the python class object as a C
> pointer[/color]

You mean, you have an instance object?
[color=blue]
> and i want to access one of the class members, somevar,[/color]

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

disgracelands
Guest
 
Posts: n/a
#3: Jul 18 '05

re: Accessing class members from C


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" <martin@v.loewis.de> wrote in message
news:biv04k$mel$05$1@news.t-online.com...[color=blue]
> disgracelands wrote:
>[color=green]
> > Basically i have the python class object as a C
> > pointer[/color]
>
> You mean, you have an instance object?
>[color=green]
> > and i want to access one of the class members, somevar,[/color]
>
> 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
>[/color]


Closed Thread