-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorators.py
More file actions
55 lines (44 loc) · 1.24 KB
/
decorators.py
File metadata and controls
55 lines (44 loc) · 1.24 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
import functools
def my_decorator(func):
@functools.wraps(func)
def function_that_runs_func():
print("im here")
func()
print("now there")
return function_that_runs_func
@my_decorator
def my_function():
print("im the function now!")
print(my_function())
def decorator_with_arguments(number):
def my_decorator(func):
@functools.wraps(func)
def function_that_runs_func2():
print("Dies")
if number == 4:
print("bestanden")
else:
func()
print("vorbei")
return function_that_runs_func2
return my_decorator
@decorator_with_arguments(20)
def my_function_too():
return 1+1
print(my_function_too)
def decorator_with_arguments(number):
def my_decorator2(func):
@functools.wraps(func)
def functions_that_runs_func(*args, **kwargs):
print("in the decorator!")
if number == 100:
print("permission")
else:
func(*args, **kwargs)
print("after decorator")
return functions_that_runs_func
return my_decorator2
@decorator_with_arguments(57)
def my_function_too(x,y):
print(x+y)
my_function_too(100,100)