defining __setattr__ in an extension

Trevor trevorperrin at hotmail.com
Thu Nov 21 05:03:25 EST 2002


Hello Python folks,

I'm trying to define a new python class in a C extension module,
following this recipe:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/54352

I'm having trouble adding a __setattr__ method.  Following Vladimir's
advice (see note 1 on the URL) I add the __getattr__ and __setattr__
functions to the class dictionary before calling PyClass_New.

When my __getattr__ function is called, the self parameter is NULL,
with self as the first argument in the args tuple.  But when
__setattr__ is called, the self parameter is still NULL, but self
*isn't* in the args tuple, which only has two args.  So I have no
self, which seems alarming.

Then I tried adding __setattr__ after the call to PyClass_New, like
any other method, and then it doesn't appear to get called at all.

So what's the appropriate way to define a __setattr__ method when
using the above idiom?


Trevor



More information about the Python-list mailing list