List vs tuples

Roy Smith roy at panix.com
Thu Apr 15 09:07:17 EDT 2004


"urnerk at qwest.net" <urnerk at qwest.net> wrote:

> As for emulating C structs, I liked the suggestion of using a class with
> only data attributes.  That's a logical analogy, as in C++, it's the struct
> that morphs into the basic class, with the addition of methods to data.
> 
> However, if you really want to used a low level C struct, there's actually a
> struct in the standard library implemented using a C struct.  

That depends on what you're trying to do.  The struct module lets you 
get at (or generate) packed binary data.  Unless you're dealing with 
binary files or network protocols, you'll probably never have a reason 
to use it.  In C terms, the functionality the struct module implements 
is essentially a union of a struct and a char array.

The degenerate class I had suggested makes a lot more sense for the more 
common case of just wanted to build an aggregate data item and be able 
to refer to the members by name.



More information about the Python-list mailing list