C API []-style access to instance objects

  • Thread starter williams.jasonscott
  • Start date
W

williams.jasonscott

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:
Traceback (most recent call last):

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~
 
G

Guest

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):

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
 
W

williams.jasonscott

That worked! Thank You!

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

thanks....
~jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,200
Latest member
SCPKatheri

Latest Threads

Top