-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorators.py
52 lines (36 loc) · 878 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
43
44
45
46
47
48
49
50
51
class Pencil:
def __init__(self, count):
self._counter=count
@property
def counter(self):
return self._counter
@counter.setter
def counter(self, count):
self._counter = count
@counter.getter
def counter(self):
return self._counter
HB = Pencil(100)
print (HB.counter)
HB.counter = 20
print (HB.counter)
# Output
# 100
# 20
# -----------------------------
class Accolade:
def __init__(self, function):
self.function = function
def __call__ (self, name):
# Adding Excellency before name
name = "Excellency " + name
self.function(name)
# Saluting after the name
print("Thanks " + name + " for gracing the occasion")
@Accolade
def simple_function(name):
print (name)
simple_function('John McKinsey')
# Output
# Excellency John McKinsey
# Thanks Excellency John McKinsey for gracing the occasion