Created
December 29, 2016 13:11
-
-
Save iivvoo/9d0aca3898f32b7108ce12084f055dd5 to your computer and use it in GitHub Desktop.
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
def classproperty(f): | |
""" | |
E.g. | |
>>> class foo(object): | |
... @classproperty | |
... def name(cls): | |
... return cls.__name__ | |
>>> print foo.name | |
'foo' | |
""" | |
class name(object): | |
def __init__(self, getter): | |
self.getter = getter | |
def __get__(self, obj, type=None): | |
return self.getter(type) | |
return name(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment