[Python-ideas] question - 'bag' type

spir ☣ denis.spir at gmail.com
Thu Apr 15 19:56:44 CEST 2010


On Wed, 14 Apr 2010 22:30:38 -0700
"C. Titus Brown" <ctb at msu.edu> wrote:

> I guess I don't understand what a bag is -- I'd just heard this structure
> referred to as such.
> 
> "dict aside from syntax" is the point, yes!

Then what you need is an interface transforming pseudo-keys into attr names. (I do that often, esp. for config objects read from text files in which the user only specifies differences from default -- then I can access config elements using object syntax -- seems to be similar to your expectations).
Just use setattr / getattr to build a generic class for such needs. It makes a flexible type for data "units" (composite objects); flexible in that the attr names are data themselves.

Denis
________________________________

vit esse estrany ☣

spir.wikidot.com



More information about the Python-ideas mailing list