Edit/Clarification to make my question specific to my query: *I can see how the decorator static log function is called but I don\'t see how _ is
def decorate(fn):
def wrapper():
fn()
print 'Wrapping function ', wrapper
return wrapper
def x():
pass
print 'Original x ', x
x = decorate(x)
print 'New x ', x
Output:
Original x
Wrapping function
New x
Note how x
is now the same as wrapper
. When you call x
, you are actually calling wrapper
.
Do not mark this answer as the answer. Mark one of the others as the answer. The point of this is to correct a misunderstanding so that you may then correctly understand one of the other answers.