Decorator
Peter Otten
__peter__ at web.de
Thu Mar 20 05:59:35 EDT 2014
muru kessan wrote:
> Is there a difference between accessing decorators via '@' symbol and
> hard coding that ? esp when the function passed to the decorator is a
> recursive one?
The difference is not the decorator but the recursive function call.
Consider
Case 1:
@deco
def f():
...
f() # calls the decorated function
...
f()
Case 2:
def f()
...
f() # calls the undecorated function
...
g = deco(f)
g()
The function call f() will invoke whatever the global name f is bound to a
the time of invocation. So
Case 3:
def f()
...
f() # calls the decorated function
...
f = deco(f)
f()
In your code change
fib1 = isOddMy(fib)
to
fib = isOddMy(fib)
and the without@ version will produce the same output as the with@ version.
More information about the Python-list
mailing list