a data type like c struct's?

John Roth johnroth at ameritech.net
Fri May 9 07:02:23 EDT 2003


"Axel Bock" <news-and-lists at the-me.de> wrote in message
news:pan.2003.05.09.09.48.15.489430 at the-me.de...
> Hi all,
>
> I have a bunch of data in a database, which was a c struct with many,
many
> integers. Now I read this data and get a string with a hassle of
binary
> data, which I want back in nice little variables, best struct-like
> (tcp_stast.sent_1, tcp_stat.recvd_2, etc.)
>
> Now could I make a class with an __init__(bunch-of-binary) and a lot
of
> struct.unpack()'s, but really I'm too lazy for this right now :)
> So I thought I might ask some people who might know better ...
>
> Well, any ideas? :-))

I'd probably put the values in a dictionary, using your
labels as keys. Although if you've actually got two arrays
(which your labels seem to suggest) using two lists might
be a better idea.

In either case, it should be easy to construct a loop to unpack
the string into a dictionary or list. You could do the same thing
with the instance variables of a class, but then you'd have to
insert the variables with setattr().

John Roth
>
>
> Greetings and thanks in advance,
>
> Axel.






More information about the Python-list mailing list