Help needed adding attributes to a C-coded class

Discussion in 'Python' started by vincent wehren, Dec 14, 2003.

  1. Hi folks,




    How can I add an attribute to a C-coded class (..using PyClass_New()...) in
    the __init__ method of that class, making it show up in "self.__dict__" on
    the Python side?

    IOW, when I have a class called "Screen" in a C-extension that has an
    __init__ method that takes a single argument called "name" (apart from
    "self" of course), how can I add this as an attribute to the class so that
    it equals a "self.name = name" assigment in a pure Python class?

    So far my "__init__" method looks something like:




    static PyObject *

    ex_Screen__init__(PyObject *self, PyObject *args)

    {

    char *name;

    PyObject *selfObject;


    if (!PyArg_ParseTuple(args, "Os", &selfObject, &name))

    return NULL;

    /*now "name" becomes one of the instances attributes

    exposed as instance.__dict__ on Python side..... but how?*/


    Py_INCREF(Py_None);

    return Py_None;

    }




    Any pointers much appreciated!




    Regards,




    Vincent Wehren
     
    vincent wehren, Dec 14, 2003
    #1
    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. Luis Esteban Valencia
    Replies:
    1
    Views:
    525
    Curt_C [MVP]
    Jan 6, 2005
  2. kelvSYC
    Replies:
    2
    Views:
    4,704
    Brad BARCLAY
    Dec 30, 2003
  3. Otuatail

    Colour coded SELECT

    Otuatail, Dec 18, 2003, in forum: HTML
    Replies:
    6
    Views:
    423
    David
    Dec 19, 2003
  4. Blinky the Shark

    If MS coded vi

    Blinky the Shark, Apr 26, 2006, in forum: HTML
    Replies:
    1
    Views:
    401
    Roy Schestowitz
    Apr 27, 2006
  5. james_027

    class attributes & data attributes

    james_027, Jun 20, 2007, in forum: Python
    Replies:
    2
    Views:
    377
    Bruno Desthuilliers
    Jun 20, 2007
Loading...

Share This Page