Skip to content

Instantly share code, notes, and snippets.

View moskytw's full-sized avatar

Mosky Liu moskytw

View GitHub Profile
@moskytw
moskytw / property-with-closure.py
Created March 2, 2013 15:33
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)
)