-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathintended_purpose.py
More file actions
51 lines (33 loc) · 923 Bytes
/
intended_purpose.py
File metadata and controls
51 lines (33 loc) · 923 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
import pprint
class Widget:
__count = 0 # _Widget__count
def __init__(self):
super().__init__()
self.__count = Widget.__count
Widget.__count += 1
@property
def widget_id(self):
return self.__count
@staticmethod
def total_widgets_created():
return Widget.__count
class Button(Widget):
def __init__(self):
super().__init__()
self.__count = 0 # _Button_count
def click(self):
self.__count += 1
def total_clicks(self):
return self.__count
def main():
print(Widget.total_widgets_created(), "widgets")
b = Button()
print(Widget.total_widgets_created(), "widgets")
print(b.total_clicks(), "clicks")
b.click()
b.click()
print(b.total_clicks(), "clicks")
print(Widget.total_widgets_created(), "widgets")
pprint.pprint(b.__dict__)
if __name__ == '__main__':
main()