a data type like c struct's?

Nat Budin natb at brandeis.edu
Sun May 11 00:39:42 EDT 2003


> 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.

Even better... and more overkill... and more ugly...

Create a new class (called, say, Record) with a dictionary as a
member.  The dictionary uses labels as keys as described above.  The
class has __getattr__ and __setattr___ overloaded so that you can
access fake "members" that act exactly in the syntax you want.

I've actually done it before - it's a bit ugly but it sure makes the
OTHER code more readable... :)

Nat




More information about the Python-list mailing list