Skip to content

Instantly share code, notes, and snippets.

@arekbulski
Created September 25, 2016 08:21
Show Gist options
  • Save arekbulski/8c0a6fc15cc59589b11169e547e33e72 to your computer and use it in GitHub Desktop.
Save arekbulski/8c0a6fc15cc59589b11169e547e33e72 to your computer and use it in GitHub Desktop.
class Container(collections.OrderedDict):
__slots__ = ["__keys_order__","__recursion_lock__"]
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
def __setattr__(self, name, value):
self[name] = value
def __delattr__(self, name):
del self[name]
def __call__(self, **kw):
"""
Chains adding new entries to the same container. See ctor.
"""
for k,v in kw.items():
self.__setitem__(k, v)
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment