473,578 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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
FlowReportRowOb jectSetAttr 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.FlowRep ortRow
print dir(row)
row.show_local_ ip = 1

And it displays:
ad@odin:share>p ython 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 2427
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 FlowReportRowOb jectSetAttr 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 FlowReportRowOb jectSetAttr 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
2415
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 options. Python built and installed fine. PyXML built and installed with no complaining but, when I give the commands below it cannot find the...
2
2352
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 Visual Studio, and extensions need to be built with the same version of the compiler, but it isn't installed. ---
48
4908
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 David Daniels where he said that probably the VS2003 toolkit will be used for Python 2.5 again. However, even before the release of Python 2.5, I...
11
7439
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 debugger, no PyDOC integration, it's class browser doesn't display attributes. On the other side there's Eric, which is made just for Python. But.. it...
1
2488
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 Boost built using g++. Here's some of my output: Student@YGGDRASIL /c/Boost/libs/python/example/tutorial $ bjam -sTOOLS=mingw -d+2 ....found...
12
2739
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 English before seeing any Python examples. Below is my attempt at generating ten fairly simple, representative Python programs that expose new users
2
1150
by: shashimail4 | last post by:
How can implement Http Attributes used by php dynamic pages? Describe breafly?
3
1284
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 ooIter field2 = val2 field3 = val3 # etc
17
2307
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 generated a skeleton class file. I was even thinking of automatically generating the shell for doc strings and epydoc tags. Is there existing...
0
1365
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: build/lib.linux-x86_64-2.5/pyodbc.so: undefined symbol: PyUnicodeUCS2_Resize I'm not quite sure how to go about troubleshooting this. More info: Build is on opensuse 11.0,...
0
7847
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7778
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8290
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1389
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.