Created
March 2, 2013 15:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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