-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorator.py
45 lines (32 loc) · 867 Bytes
/
decorator.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
43
44
45
# Example for function as object
def hello():
print('Hello World')
hello()
print(hello)
greet = hello
print('After deleting hello() function')
del hello
print('Calling greet() after deleting hello')
greet()
#hello()
def original_func():
print('This is original function')
def decorator_func(some_func):
def wrapper_func():
print('This is starting of wrapper function')
some_func()
print('This is end of wrapper function')
return wrapper_func
new_decorated_func = decorator_func(original_func)
new_decorated_func()
# The above function can also be decorated as:
print('After adding @ operator')
@decorator_func
def original_func():
print('This is original function')
original_func()
print('After removing @ operator')
#@decorator_func
def original_func():
print('This is original function')
original_func()