-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathconfig_v3.py
More file actions
33 lines (27 loc) · 817 Bytes
/
config_v3.py
File metadata and controls
33 lines (27 loc) · 817 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
class Config:
def __init__(self, name):
self.name = name
def set_option(self, key, value):
setattr(self, key, value)
def get_option(self, key):
return getattr(self, key, None)
def remove_option(self, key):
if hasattr(self, key):
delattr(self, key)
print(f"'{key}' removed!")
else:
print(f"'{key}' does not exist.")
def clear(self):
for key in list(self.__dict__.keys()):
delattr(self, key)
print("All options removed!")
conf = Config("GUI App")
conf.set_option("theme", "dark")
conf.set_option("size", "200x400")
print(conf.__dict__)
conf.remove_option("size")
print(conf.__dict__)
conf.remove_option("autosave") # Raises KeyError
print(conf.__dict__)
conf.clear()
print(conf.__dict__)