0

decorator function

I have written a code dec.fail3.py And can't understand why it's not running def decor(func) : def wrap () : print("???????????????????") func() print("???????????????????") return wrap def mysteries_func: print("mysteries") decoration = decor (mysteries_func) decoration () The code playground said there was an error with decoration () I'd put it in the format in the example but it doesn't work because of the last line? I'm lost here

9th Jun 2020, 9:06 AM
Claire
Claire - avatar
8 Respuestas
+ 2
def decor (func): def wrap(): print ("?????????????????????") func() print("???????????????????") return wrap def mysteries_func(): print("mysteries of the universe") decorator=decor(mysteries_func) decorator()
9th Jun 2020, 9:30 AM
Abhay
Abhay - avatar
+ 1
It should be decoration() not decoration=() Also def decor(): not def decor:
9th Jun 2020, 9:08 AM
Abhay
Abhay - avatar
+ 1
Oh you need to pass function you want to decorate to decorator function as well So it should be def decor(func):
9th Jun 2020, 9:15 AM
Abhay
Abhay - avatar
+ 1
It's best if you upload your code in Code Playground and link it here. That way, we can be sure there are no formatting errors or anything that get lost when you copypaste. Also it makes testing your code easier for anyone who's going to help you.
9th Jun 2020, 9:52 AM
HonFu
HonFu - avatar
0
I'll try but the problem seems to. Be with decorated () holding no value
9th Jun 2020, 9:10 AM
Claire
Claire - avatar
0
Yes I had put it in as that and as decorator(). The above code has been edited to what I put, sorry about that
9th Jun 2020, 9:24 AM
Claire
Claire - avatar
0
So I did that and it's still not running
9th Jun 2020, 9:28 AM
Claire
Claire - avatar
0
Still not working for me? What have I done wrong? I'll take another loook
9th Jun 2020, 9:34 AM
Claire
Claire - avatar