-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (20 loc) · 704 Bytes
/
utils.py
File metadata and controls
27 lines (20 loc) · 704 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
import os
from json import loads, dumps
from os.path import exists
class Config:
def __init__(self, filename):
self.filename = filename
if not exists(filename):
with open(filename, 'w', encoding='utf8') as f:
f.write('{}')
with open(filename, 'r', encoding='utf8') as f:
self.data = loads(f.read())
def __setitem__(self, key, value):
self.data[key] = value
def __getitem__(self, item):
return self.data[item]
def __contains__(self, item):
return item in self.data
def save(self):
with open(self.filename, 'w', encoding='utf8') as f:
f.write(dumps(self.data, indent=4))