decorator - Py i
This commit is contained in:
parent
fc05b23930
commit
228eef0258
|
@ -0,0 +1,11 @@
|
|||
def decorator(func):
|
||||
def wrapper():
|
||||
print("Something is happening before the function is called.")
|
||||
func()
|
||||
print("Something is happening after the function is called.")
|
||||
return wrapper
|
||||
|
||||
def say_whee():
|
||||
print("Whee!")
|
||||
|
||||
say_whee = decorator(say_whee)
|
|
@ -1,11 +1,11 @@
|
|||
def parent():
|
||||
print("Printing from parent()")
|
||||
|
||||
def parent(num):
|
||||
def first_child():
|
||||
print("Printing from first_child()")
|
||||
return "Hi, I'm Elias"
|
||||
|
||||
def second_child():
|
||||
print("Printing from second_child()")
|
||||
return "Call me Ester"
|
||||
|
||||
second_child()
|
||||
first_child()
|
||||
if num == 1:
|
||||
return first_child
|
||||
else:
|
||||
return second_child
|
||||
|
|
Loading…
Reference in New Issue