Total newbie herem trying to understand the flow of execution,, look at the following code:
from datetime import datetime
from time import *
def time_decorator(function,a=0):
a +=1
print(a)
def wrapper(*args,**kwargs):
t1= time()
result = function(*args,**kwargs)
t2 = time() - t1
print("elapsed:", t2)
return result
a +=2
print(a)
return wrapper
@time_decorator
def add(x, y=10):
sleep(2)
return x + y
print (add(10))
The output is like this:
1
3
elapsed: 2.0001702308654785
20
1
3
my question is why the last vaues of 'a' are the same in the last 2 lines??, i was expectin to be increased by two more?...im not understanding the flow of excution of the interpreter, help!!