Help needed adding attributes to a C-coded class

V

vincent wehren

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
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top