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

Andrew Degtiariov ad at astral-on.net
Fri Sep 17 09:28:48 EDT 2004


On Fri, Sep 17, 2004 at 12:43:56PM +0000, Michael Hudson wrote:
> 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?
yes, Python 2.3

> 
> > 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.
Thanks you for tips. 

-- 
Andrew Degtiariov 
DA-RIPE



More information about the Python-list mailing list