Last active
July 19, 2017 14:19
-
-
Save verdimrc/46a75c0572a33336e9010d51ef75cc6f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 printcall(f): | |
def f_wrapper(*args, **kwargs): | |
print('Running {}...'.format(f.__name__)) | |
retval = f(*args, **kwargs) | |
print('Finished {}.'.format(f.__name__)) | |
return retval | |
return f_wrapper | |
# The rest are based on http://stackoverflow.com/a/14349742 | |
class Foo(object): | |
def _get_meow(self): | |
return self._meow + ' HEHEHE from a Foo' | |
def _set_meow(self, value): | |
self._meow = value | |
@printcall | |
def _decorated_get_meow(self): | |
return self._get_meow() | |
meow = property(fget=lambda self: self._get_meow(), | |
fset=lambda self, value: self._set_meow(value)) | |
# Addition to SO's code fragment | |
dmeow = property(fget=lambda self: self._decorated_get_meow()) | |
class Bar(Foo): | |
def _get_meow(self): | |
return super()._get_meow() + ', HAHAHA altered by a Bar' | |
if __name__ == '__main__': | |
foo = Foo() | |
bar = Bar() | |
foo.meow, bar.meow = 'meow', 'meow' | |
print(foo.meow) | |
print(bar.meow) | |
print() | |
print(foo.dmeow) | |
print(bar.dmeow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment