forked from kumaya/python-programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageProperty.py
More file actions
Latest commit
53 lines (40 loc) · 1008 Bytes
/
Copy pathUsageProperty.py
File metadata and controls
53 lines (40 loc) · 1008 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
What @property decorator really is and how it works
"""
classUsagePropertyDeco(object):
def__init__(self, name_is=None):
print"Inside __init__"
self.name=name_is
defa(self):
print"inside A: 1"
defb(msg):
print"Inside B: 1"
returnmsg
print"Inside A: 2"
returnb
@property
defc(self):
print"Inside C: 1"
returnself.a()
classAlternateToPropertyDeco(object):
def__init__(self, name_is):
print"Inside __init__"
self.name=name_is
@property
defa(self):
print"Getter invoked"
returnself.name
@a.setter
defa(self, val):
print"Setter invoked"
self.name=val
if__name__=="__main__":
name="Mayank"
obj=UsagePropertyDeco(name)
msg="My name is mayank kumar"
printobj.c(msg)
print"*"*80
obj=AlternateToPropertyDeco(name)
printobj.a
obj.a="maya"
printobj.a