Re: C API []-style access to instance objects

2006-04-27 Thread André Malo
* [EMAIL PROTECTED] 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C API []-style access to instance objects

2006-04-27 Thread [EMAIL PROTECTED]
That worked! Thank You!

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

thanks
~jason

-- 
http://mail.python.org/mailman/listinfo/python-list


C API []-style access to instance objects

2006-04-26 Thread [EMAIL PROTECTED]
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~

-- 
http://mail.python.org/mailman/listinfo/python-list