tp_getattrfunc, access members that are a list
Thomas Heller
theller at python.net
Wed Jun 9 03:35:18 EDT 2004
Torsten Mohr <tmohr at s.netic.de> writes:
>>> Can anybody describe me how i can access the array d[8]
>>> as a list? I'd like to get AND set values in there.
>>
>> I don't think you can expose them as a list, but you should look into
>> structmember.h, and it's PyMemberDef to expose the items separately.
>
> Hi,
>
> i've looked into structmember.h, but nothing (like e.g. a flag)
> can mark that member as an array.
> Also, i can't just export every single array member, as i need
> to access them indexed, e.g. in a for() for clearing, for
> setting calculated values, ...
>
> In the documentation i read that accessing arrays should be done
> by getattr/setattr functions. This must be possible somehow...
Ok, structmember.h was the wrong hint - it is used to expose
heterogenous fields.
For sequence like behaviour, you must implement PySequenceMethods:
sq_length, sq_item, sq_add_item for example.
Thomas
More information about the Python-list
mailing list