+ 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();

4th Aug 2018, 3:51 AM
Daniel Yang
Daniel  Yang - avatar
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()
5th Aug 2018, 7:16 PM
Benneth Yankey
Benneth Yankey - avatar
0
Ah~thanks
6th Aug 2018, 2:16 AM
Daniel Yang
Daniel  Yang - avatar