Need a structure with multiple members
Thomas Gagne
tgagne at ix.netcom.com
Mon Aug 7 22:36:45 EDT 2000
The struct module is interesting for creating a string encoded with binary
data, but the pack() and unpack() functions don't seem to describe how once
created you would safely access members of that structure.
For instance, I want to create a class that mirrors the C header:
typedef struct {
int32_t len;
int32_t sequence;
int16_t reply;
int16_t error;
/* blah blah blah for 64 bytes total */
} isdHeader;
It as though I coudl start my isdHeader class as:
class IsdHeader:
def __init__(self):
self.data = struct.pack('llhh', 0, 0, 0, 0)
But I would like to create member functions (methods) for accessing the
various members, such that:
h = IsdHeader();
h.len(20) // sets h.len to 20
h.len() // returns the value of h.len (the member)
I'm kinda of reading, "Quick Python" and trying to code the interface library
at the same time, and I haven't read everything yet...
More information about the Python-list
mailing list