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

Andrew Degtiariov ad at astral-on.net
Fri Sep 17 08:14:43 EDT 2004


Hello!
I tried to rewrite my python module in C. 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)

I wrote simple test:
import Reports


row = Reports.FlowReportRow
print dir(row)
row.show_local_ip = 1

And it displays:
ad at odin:share>python test.py 
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'add', 'add2']
Traceback (most recent call last):
  File "test.py", line 6, in ?
      row.show_local_ip = 1
      TypeError: can't set attributes of built-in/extension type
      'FlowReportRow'
ad at odin:share>

-- 
Andrew Degtiariov 
DA-RIPE



More information about the Python-list mailing list