Accessing class members from C

Discussion in 'Python' started by disgracelands, Sep 1, 2003.

  1. 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
    disgracelands, Sep 1, 2003
    #1
    1. Advertising

  2. 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
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Sep 1, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:biv04k$mel$05$-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
    >
    disgracelands, Sep 1, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernd Fuhrmann
    Replies:
    3
    Views:
    404
    Roedy Green
    Oct 15, 2005
  2. John Harrison
    Replies:
    18
    Views:
    542
    Pete Becker
    Aug 11, 2003
  3. CoolPint
    Replies:
    8
    Views:
    957
    Jeff Schwab
    Dec 14, 2003
  4. hdixon
    Replies:
    3
    Views:
    628
    hdixon
    Jul 9, 2006
  5. Bhawna
    Replies:
    7
    Views:
    460
    Bhawna
    Aug 26, 2008
Loading...

Share This Page