Created
March 10, 2019 00:41
-
-
Save happymishra/e4d441e552f999306a4c53bc6196cc5c 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
import inspect | |
def decorator_wrapper(parameter): | |
print parameter | |
def decorator(func): | |
def wrapper(message): | |
print "Wrapper start" | |
func(message) | |
print "Wrapper end" | |
return wrapper | |
return decorator | |
# Here, instead of having the decorator function object as in prevision cases, | |
# we are executing the decorator_wrapper function using the round brackets which returns the | |
# decorator function. So ultimately the code changes to | |
''' | |
decorator = decorator_wrapper("Decorator paramerter") | |
@decorator | |
def say_hello(message): | |
print message | |
''' | |
@decorator_wrapper("Decorator parameter") | |
def say_hello(message): | |
print message | |
print inspect.getsource(say_hello) | |
''' | |
def wrapper(message): | |
print "Wrapper start" | |
func(message) | |
print "Wrapper end" | |
''' | |
say_hello("Hello, world") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment