-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorators.py
43 lines (30 loc) · 871 Bytes
/
decorators.py
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
39
40
41
42
import functools
def my_decorator(func):
@functools.wraps(func)
def function_that_runs_fun():
print("In the decorator!")
func()
print("After the decorator!")
return function_that_runs_fun
@my_decorator
def my_function():
print("I'm the function!")
#my_function()
##
def decorator_with_arguments(number):
def my_decorator(func):
@functools.wraps(func)
def function_that_runs_func(*args, **kwargs):
print("In the decorator!")
if number == 56:
print("Not run the function!")
else:
func(*args, **kwargs)
print("After the decorator!")
return function_that_runs_func
return my_decorator
@decorator_with_arguments(57)
def my_function_too(x, y):
a = x + y
print("Hello! " + str(a))
my_function_too(11, 22)