Лекция 4
Вспомогательный материал к лекции
1. pause.py
#!/usr/bin/env python
import time
from profile import timer
def pause(t):
def wrapper(f):
def tmp(*args, **kwargs):
time.sleep(t)
return f(*args, **kwargs)
return tmp
return wrapper
@timer
@pause(1)
def func(x, y):
return x**y
if __name__ == "__main__":
print func(2,10)
2.profile.py
#!/usr/bin/env python
import time
def timer(f):
def wrapper(*args, **kwargs):
t = time.time()
res = f(*args, **kwargs)
print "Time elapsed: %f" % (time.time() - t)
return res
return wrapper
@timer
def func(x, y):
return x**y
if __name__ == "__main__":
print func(2,10)