-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecorador.py
More file actions
38 lines (34 loc) · 829 Bytes
/
Decorador.py
File metadata and controls
38 lines (34 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Special Closure
def decorator(func):
def envoltura():
print('Hello')
func()
return envoltura
def saludo():
print('Hola!')
saludo = decorator(saludo)
saludo()
#Sugar sintax
def decorator(func):
def envoltura():
print('Hello')
func()
return envoltura
@decorator #The same but different sintax
def saludo():
print('Hola!')
saludo()
from datetime import datetime
def execution_time(func):
def wrapper(*args, **kwargs):
initial_time = datetime.now()
func(*args, **kwargs)
final_time = datetime.now()
time_elapsed = final_time - initial_time
print(f'Pasaron {time_elapsed.total_seconds()} segundos')
return wrapper
@execution_time
def random_func():
for _ in range(1, 10000000):
pass
random_func()