News for hackers. Stuff that matters.
Re:Python Tips and Traps by timdierks on Tuesday January 20, 2015 @12:38PM (#8918120)
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']

There are no comments on this comment yet.