Created
October 1, 2021 07:25
-
-
Save VerosK/e102dffc1031f9a88ac26bf5d94f1eb4 to your computer and use it in GitHub Desktop.
Art decoators
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
# see https://naucse.python.cz/course/mi-pyt/intro/magic/ | |
import functools | |
def art_deco(func): | |
print(f"Decorating {func.__name__}") | |
@functools.wraps(func) | |
def inner(*args, **kwargs): | |
print(f"Starting {func.__name__}") | |
retv = func(*args, **kwargs) | |
print(f"Result {func.__name__} is {retv}") | |
return retv | |
return inner | |
@art_deco | |
def foo(a): | |
"This is very important function!" | |
print(f"foo: a is {a}") | |
return a | |
if __name__ == '__main__': | |
# print("main is starting") | |
print(f'foo is {foo.__name__}') | |
print(f'doc in foo is {foo.__doc__}') | |
#foo(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment