Last active
June 13, 2019 23:18
-
-
Save diogobaltazar/8ecf03828f664460b00b15da370eb98c to your computer and use it in GitHub Desktop.
Python decorators | passing functions as arguments
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
def f(func = None): | |
if func != None: | |
func() | |
print('executing f') | |
def g(): | |
print('executing g') | |
return g | |
g = f() | |
g() | |
f(g) | |
# executing f | |
# executing g | |
# executing g | |
# executing f | |
def h(f): | |
def wrap_f(): | |
print('executing h') | |
f() | |
print('h was executed') | |
return wrap_f | |
@h | |
def t(): | |
print('executing t') | |
t() | |
# executing h | |
# executing t | |
# h was executed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment