in Ruby, there's this awesome library called a Mash which is a Hash but through clever use of missing_method can convert:
object['property']
to
object.property
This is really useful for mocks. Anyone know of a similar kind of thing in Python?
Is it absolutely necessary that you base this on a dict? Python objects can dynamically acquire attributes with very little extra plumbing:
>>> class C(object): pass
...
>>> z = C()
>>> z.blah = "xyzzy"
>>> dir(z)
['__class__', '__delattr__', '__dict__', ... '__weakref__', 'blah']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With