Help needed adding attributes to a C-coded class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vincent wehren

    Help needed adding attributes to a C-coded class

    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.__dic t__" 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_ParseTu ple(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_No ne);

    return Py_None;

    }




    Any pointers much appreciated!




    Regards,




    Vincent Wehren






































Working...