3 ms·
I frequently want ad-hoc slots to create a structure of related values without the verbosity of a dict with static keys. What's the pythonic method? E.g. when
by timdierks 12y ago
I frequently want ad-hoc slots to create a structure of related values without the verbosity of a dict with static keys. What's the pythonic method?
E.g. when I want to carry a foo, a bar, and a baz around, but namedtuple isn't right (e.g. I need mutation). I'd prefer
config = Someclass()
config.foo = 1
config.bar = "quux"
config.baz = 3.3
and then using config.bar, etc.
over:
config = { 'foo': 1, 'bar': "quux", 'baz': 3.3 }
and then using config['bar']