Skip to content

Instantly share code, notes, and snippets.

@moskytw
Created March 2, 2013 15:33
Show Gist options
  • Save moskytw/5071553 to your computer and use it in GitHub Desktop.
Save moskytw/5071553 to your computer and use it in GitHub Desktop.
A dirty hack which uses closure maps the accessing on an attribute to the __*item__ methods.
setattr(DictLike, attrname,
# it is a colsure
(lambda x:
property(
lambda self: self.__getitem__(x),
lambda self, v: self.__setitem__(x, v),
lambda self: self.__delitem__(x)
)
)(attrname)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment