Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help needed adding attributes to a C-coded class

Reply
Thread Tools

Help needed adding attributes to a C-coded class

 
 
vincent wehren
Guest
Posts: n/a
 
      12-14-2003
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






































 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding method from one class to another class or to instance ofanother class marekw2143 Python 3 07-25-2009 08:33 PM
decorator to prevent adding attributes to class? Neal Becker Python 5 07-12-2008 04:00 AM
Adding attributes stored in a list to a class dynamically. Nathan Harmston Python 7 09-03-2007 03:03 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments