tp_getattrfunc, access members that are a list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Mohr

    tp_getattrfunc, access members that are a list

    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.

  • Thomas Heller

    #2
    Re: tp_getattrfunc, access members that are a list

    Torsten Mohr <tmohr@s.netic. de> writes:
    [color=blue]
    > 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.[/color]

    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


    Comment

    • Torsten Mohr

      #3
      Re: tp_getattrfunc, access members that are a list

      >> Can anybody describe me how i can access the array d[8][color=blue][color=green]
      >> as a list? I'd like to get AND set values in there.[/color]
      >
      > 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.[/color]

      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.

      Comment

      • Thomas Heller

        #4
        Re: tp_getattrfunc, access members that are a list

        Torsten Mohr <tmohr@s.netic. de> writes:
        [color=blue][color=green][color=darkred]
        >>> 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.[/color]
        >>
        >> 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.[/color]
        >
        > 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...[/color]

        Ok, structmember.h was the wrong hint - it is used to expose
        heterogenous fields.

        For sequence like behaviour, you must implement PySequenceMetho ds:
        sq_length, sq_item, sq_add_item for example.

        Thomas


        Comment

        Working...