473,406 Members | 2,273 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,406 software developers and data experts.

C API []-style access to instance objects

Hi,

I am having trouble figuring out how to set up an object to be
scriptable through the C API. An example of what I am attempting to
do:
obj = foo.Foo()
obj["key"] Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsubscriptable object


I've tried defining __getitem__ as a method, but that hasn't worked.
Is there a tp_field that I am failing to understand, something like
tp_iter and tp_iternext?

thanks~

Apr 26 '06 #1
2 1018
* wi*****************@gmail.com wrote:
Hi,

I am having trouble figuring out how to set up an object to be
scriptable through the C API. An example of what I am attempting to
do:
obj = foo.Foo()
obj["key"] Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsubscriptable object


I've tried defining __getitem__ as a method, but that hasn't worked.
Is there a tp_field that I am failing to understand, something like
tp_iter and tp_iternext?


tp_as_mapping is what you're looking for. It takes the pointer to another
structure: PyMappingMethods.

You might want to try the modulator script (comes with the source
distribution of python), which generates some of the basic type methods for
you. It's a bit old, but gives a good start.

nd
--
"Umfassendes Werk (auch fuer Umsteiger vom Apache 1.3)"
-- aus einer Rezension

<http://pub.perlig.de/books.html#apache2>
Apr 27 '06 #2
That worked! Thank You!

I'd also like to say this group is great at fast accurate responses!
Cheers!

thanks....
~jason

Apr 27 '06 #3

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

Similar topics

0
by: Evin | last post by:
How can I access values from variables (global variables) from other running applications (Java Script in IE). I need to get the value using VB.NEt is it possible. B'coz the server generates...
9
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access...
4
by: MikeAth via DotNetMonster.com | last post by:
Hi all, I have two different classes and one instance of the Form. I would like to access the members of the Form instance in both classes without having to create a new instance in the other...
2
by: Kurt Schroeder | last post by:
Is there a way to set the default style for all textboxes on a page, and a different one for all labels? Like the way the body style controls all body text. 1. given: I have a style called .smlbl...
0
by: Ersin Gençtürk | last post by:
hi , I am using internet explorer by referencing the shdocvw.dll , I can access DOM objects , but also I need to access jscript objects , for example an array object defined between the script...
4
by: VK | last post by:
Is my understanding correct that due to the lack of CSS2 support Opera doesn't allow any access to inline/linked style declarations? Say in case: <style type="text/css"> ..foo { color: blue; }...
2
by: Roger | last post by:
How can I access subreport objects from vba? Sample code would be appreciated.
2
by: TheDrizzle | last post by:
Hey All, I am using ADF UIX, which is a Oracle Framework to develop a web application. It is based off XML and translates the XML to HTML upon execution. The problem I'm having is it is creating...
2
by: Stubbs54 | last post by:
Hi, I'm currently creating a database to manage a large filing system (so about 2,500 pdf documents). I was going to link the documents in as OLE objects; however, the 2 GB limit in Access has...
5
Soniad
by: Soniad | last post by:
Hi, I have created a function which connects to excel DB and fecth records from excel file. Now, I access this function in a SUB routine.Everything is fine ,but after doing the process I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.