473,382 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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@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@odin:share>

--
Andrew Degtiariov
DA-RIPE
Jul 18 '05 #1
2 2411
Andrew Degtiariov <ad@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
Jul 18 '05 #2
On Fri, Sep 17, 2004 at 12:43:56PM +0000, Michael Hudson wrote:
Andrew Degtiariov <ad@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
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mfjacobs | last post by:
Hello, I was hoping someone here can help me with a problem I am having with the PyXML extension ( ver 0.8.4) and Python 2.4 Thsi is a brand new build of Python. Build with default .configre...
2
by: . | last post by:
Hi, how can I build python modules on windows? I tried to build numarray using Microsoft Visual C++ 2003 Toolkit, but got the following error: --- error: Python was built with version 7.1 of...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
11
by: Bart Ogryczak | last post by:
Hi, Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have drawbacks. KDevelop is a multilanguage IDE, and doesn't really have anything special for Python. There's no Python...
1
by: Max Wilson | last post by:
Hi, Has anyone here built Boost.Python modules under MinGW? I'm trying to build the Boost.Python tutorial under MinGW and getting an error that says it depends on MSVC, which puzzles me because...
12
by: Steve Howell | last post by:
I've always thought that the best way to introduce new programmers to Python is to show them small code examples. When you go to the tutorial, though, you have to wade through quite a bit of...
2
by: shashimail4 | last post by:
How can implement Http Attributes used by php dynamic pages? Describe breafly?
3
by: dmitrey | last post by:
Hi all, I have the code like this one: from myMisc import ooIter class MyClass: def __init__(self): pass iterfcn = lambda *args: ooIter(self) # i.e pass the class instance to other func named...
17
by: Sunburned Surveyor | last post by:
I was thinking of a way I could make writing Python Class Files a little less painful. I was considering a Ptyhon script that read a file with a list of property names and method names and then...
0
by: john.goodleaf | last post by:
I've just built pyodbc 2.0.58 against freetds and unixodbc. When I attempt to invoke it, either from the test script or from the interpreter, I get: ImportError:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.