Created
December 11, 2013 16:38
-
-
Save zenwerk/7913823 to your computer and use it in GitHub Desktop.
Python Class Decorator
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
class test(object): | |
"""A property whose value is computed only once. """ | |
def __init__(self, function): | |
self._function = function | |
def __get__(self, obj, _=None): | |
if obj is None: | |
return self | |
value = self._function(obj) | |
setattr(obj, self._function.func_name, value) | |
return value | |
def __call__(self): | |
print self._function | |
print "this is test class" | |
@test | |
def hoge():pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment