tp_getattrfunc, access members that are a list

T

Torsten Mohr

Hi,

in the documentation and the examples that describe how to
make the members of a new type accessible it says that
i need to use the getattrfunc and setattrfunc if i want
to access members that are an array.

typedef struct {
PyObject_HEAD
unsigned char d[8];
} pmod_obj;

Sadly i did not find any example on how to do this.

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.


Thanks for any hints,
Torsten.
 
T

Thomas Heller

Torsten Mohr said:
Hi,

in the documentation and the examples that describe how to
make the members of a new type accessible it says that
i need to use the getattrfunc and setattrfunc if i want
to access members that are an array.

typedef struct {
PyObject_HEAD
unsigned char d[8];
} pmod_obj;

Sadly i did not find any example on how to do this.

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.

Thomas
 
T

Torsten Mohr

Can anybody describe me how i can access the array d[8]
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...


Best regards,
Torsten.
 
T

Thomas Heller

Torsten Mohr said:
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
 
T

Torsten Mohr

Hi,
For sequence like behaviour, you must implement PySequenceMethods:
sq_length, sq_item, sq_add_item for example.

thanks for that hint, i'll try that one.


Best regards,
Torsten.
 

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,201
Messages
2,571,049
Members
47,654
Latest member
LannySinge

Latest Threads

Top