Created
March 21, 2020 05:14
-
-
Save quettabit/cbdfb805b0c3ada6106a56fb82761fc8 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 hello_decorator(func): | |
# inner1 is a Wrapper function in | |
# which the argument is called | |
# inner function can access the outer local | |
# functions like in this case "func" | |
print("wooow") | |
def inner1(a): | |
print("Hello, this is before function execution") | |
# calling the actual function now | |
# inside the wrapper function. | |
x = func(1) | |
print("This is after function execution") | |
return x | |
return inner1 | |
# defining a function, to be called inside wrapper | |
def function_to_be_used(a, b=10): | |
print("This is inside the function !!") | |
print(a + b) | |
return b | |
# passing 'function_to_be_used' inside the | |
# decorator to control its behavior | |
function_to_be_used = hello_decorator(function_to_be_used) | |
# calling the function | |
x = function_to_be_used(1) | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment