Why arn\'t the following two scripts equivalent?
(Taken from another question: Understanding Python Decorators)
def makebold(fn):
def wrapped():
The problem with the second example is that
@makebold
def makeitalic(fn):
def wrapped():
return "" + fn() + ""
return wrapped
is trying to decorate makeitalic
, the decorator, and not wrapped
, the function it returns.
You can do what I think you intend with something like this:
def makeitalic(fn):
@makebold
def wrapped():
return "" + fn() + ""
return wrapped
Here makeitalic
uses makebold
to decorate wrapped
.