Is there a difference between these two location of a decorator ?
def a():
@decorator_function # HERE
def b():
pass
return b
@decorator_function # OR HERE ?
c = a()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As BrenBren said, your code doesn’t work. In any case, first, decorator syntax is just syntactical sugar.
is equivalent to
So even assuming correct syntax, the first example is decorating the enclosed function
b()while the second would be decorating the closurea(). So:is the same as
and
is the same as