Cool object trick
has
has.temp2 at virgin.net
Fri Dec 17 10:14:41 EST 2004
Jive wrote:
> # Is that really much different from this?
Functionally, no. However it can help make code more readable when
dealing with complex data structures, e.g. compare:
obj.spam[1].eggs[3].ham
to:
obj["spam"][1]["eggs"][3]["ham"]
I've used it a couple times for this particular reason and it
definitely has its niche; though I'm not sure it's sufficiently common
or useful to justify its inclusion it in the standard library, and it's
trivial to whip up as-and-when it's needed.
BTW & FWIW, I think the usual name for this kind of structure is
'record' (or 'struct' in C).
HTH
has
More information about the Python-list
mailing list