-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathbasic_usage.py
More file actions
47 lines (33 loc) · 858 Bytes
/
basic_usage.py
File metadata and controls
47 lines (33 loc) · 858 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
class Base:
def f(self, x):
print("Base.f", self, x)
class Derived(Base):
def f(self, x):
print("Derived.f", self, x)
super().f(x)
print("Derived.f finished")
def basic_example():
d = Derived()
d.f(42)
class LoggingDict(dict):
def __setitem__(self, key, value):
print(f'Setting {key}: {value}')
super().__setitem__(key, value)
def __getitem__(self, item):
print(f'Getting {item}')
return super().__getitem__(item)
def __delitem__(self, key):
print(f'Deleting {key}')
super().__delitem__(key)
def logging_dict_example():
print("LOGGING DICT EXAMPLE")
d = LoggingDict()
d[0] = "subscribe"
x = d[0]
del d[0]
print()
def main():
# basic_example()
logging_dict_example()
if __name__ == '__main__':
main()