Skip to content

Instantly share code, notes, and snippets.

@diogobaltazar
Last active June 13, 2019 23:18
Show Gist options
  • Save diogobaltazar/8ecf03828f664460b00b15da370eb98c to your computer and use it in GitHub Desktop.
Save diogobaltazar/8ecf03828f664460b00b15da370eb98c to your computer and use it in GitHub Desktop.
Python decorators | passing functions as arguments
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