[implement python code in C] can't set attributes of built-in/extension type

Michael Hudson mwh at python.net
Fri Sep 17 14:43:56 CEST 2004


Andrew Degtiariov <ad at astral-on.net> writes:

> Hello!
> I tried to rewrite my python module in C. 

Are you targetting Python 2.2 or later?

> My module is successfully imported but i can't assing anything to
> class attributes (tp_setattr in PyTypeObject for class FlowReportRow
> filled up by pointer to FlowReportRowObjectSetAttr function and
> printf in ones show the function does not called) Where I was
> mistaken? (you may see the module sources at
> http://astral.ua/~ad/Report.c)

Argh!  You're making life very tedious for yourself...

Do you know what you can do with the tp_members and tp_getsets field
of the type object?  I think a C macro expanding to a couple getset
defintions would make your code more pleasant.

I think implementing tp_getattro and not tp_getattr will solve your
immediate problem.

Cheers,
mwh

-- 
  MAN:  How can I tell that the past isn't a fiction designed to
        account for the discrepancy between my immediate physical
        sensations and my state of mind?
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 12



More information about the Python-list mailing list