+ 1
What if the function I want to decorate with takes two or more functions as variables?
What if I add one more variable to the decor function? Can I decorate two functions at a time with decor? def decor(func): def wrap(): print("============") func() print("============") return wrap @decor def print_text(): print("Hello world!") print_text();
2 Answers
+ 1
If I understand correctly, with the '@' decorator syntax, you couldn't decorate more than one function at the same time. But the below will work though:
def decorator(func1, func2):
def wrapper():
print("wrapper text")
func1()
func2()
return wrapper;
def printMessage():
print("Hello message")
def printQuotes():
print("Hello Quotes")
allMsg = decorator(printMessage, printQuotes)
allMsg()
0
Ah~thanks