Dictionary-like Object In Python That Allows Setting Arbitrary Attributes
What I want to do in my code: myobj = () myobj.randomattr = 1 print myobj.randomattr ... I can implement a custom SomeClass that implements __setattr__ __g
Solution 1:
You can just use an empty class:
classA(object): pass
a =A()
a.randomattr = 1
Solution 2:
I like using the Bunch idiom for this. There are list of variations and some discussion here.
Post a Comment for "Dictionary-like Object In Python That Allows Setting Arbitrary Attributes"