-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathproperty_test.py
More file actions
46 lines (40 loc) · 845 Bytes
/
Copy pathproperty_test.py
File metadata and controls
46 lines (40 loc) · 845 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
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 16 00:50:08 2013
@author: akels
"""
class Person:
def __init__(self, name):
self._name = name
print(self.name.setter)
@property
def name(self):
"name property docs"
print('fetch...')
return self._name
@name.setter
def name(self, value):
print('change...')
self._name = value
@name.deleter
def name(self):
print('remove...')
del self._name
bob = Person('Bob Smith')
print(bob.name)
bob.name = 'Robert Smith'
print(bob.name)
del bob.name
print('-'*20)
sue = Person('Sue Jones')
print(sue.name)
print(Person.name.__doc__)
# name = property(name)
# name = name.setter(name)
# name = name.deleter(name)
# bob has a managed attribute
# Runs name getter (name 1)
# Runs name setter (name 2)
# Runs name deleter (name 3)
# sue inherits property too
# Or help(Person.name)