Last active
November 26, 2022 13:31
-
-
Save qnkhuat/634f6efd836abcf99c09631092016ea4 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 log(func_name=""): | |
def decorator(func): | |
def wrapper(*args, **kwargs): | |
func_sig = f"{func_name} | " if func_name else "" | |
print(f"{func_sig}Args: {args} {kwargs}") | |
result = func(*args, **kwargs) | |
print(f"{func_sig}Result: {result}") | |
return result | |
return wrapper | |
return decorator | |
@log("add") | |
def add(x): | |
return x + 1 | |
# add | Args: (1,) {} | |
# add | Result: 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment