what is the python equivelant of this?
Janne Sinkkonen
janne at nnets.fi
Thu Oct 12 13:56:57 EDT 2000
jschmitt at vmlabs.com writes:
> typedef struct
> {
> int field1;
> char* field2;
> } RECORD;
>
> RECORD records[] =
> {
> { 10, "gumby" },
> { 20, "barny" }
> /* etc */
> };
It could be for example
class RECORD:
def __init__(self, args):
self.field1, self.field2 = args
records = map(RECORD, ((10, 'gumby'), (20, 'barny')))
but usually it's just
records = ((10, 'gumby'), (20, 'barny'))
> RECORD* recordarray = malloc( sizeof(RECORD) * 10 );
> memset( recordarray0, sizeof(RECORD) * 10 );
That depends on the type of record - Python does not define a mapping
of objects to memory on the byte level.
recordarray = []
for i in xrange(10): recordarray.append((0,''))
or some such.
--
Janne
More information about the Python-list
mailing list