28 lines
821 B
Python
28 lines
821 B
Python
import json
|
|
|
|
class Settings(dict):
|
|
SETTINGS_FILE = "settings.json"
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.load() # Load settings from file during initialization
|
|
|
|
def save(self):
|
|
try:
|
|
j = json.dumps(self, indent=4)
|
|
with open(self.SETTINGS_FILE, 'w') as file:
|
|
file.write(j)
|
|
print("Settings saved successfully.")
|
|
except Exception as e:
|
|
print(f"Error saving settings: {e}")
|
|
|
|
def load(self):
|
|
try:
|
|
with open(self.SETTINGS_FILE, 'r') as file:
|
|
loaded_settings = json.load(file)
|
|
self.update(loaded_settings)
|
|
print("Settings loaded successfully.")
|
|
except Exception as e:
|
|
print(f"Error loading settings {e}")
|
|
self.save()
|