-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
44 lines (32 loc) · 897 Bytes
/
config.py
File metadata and controls
44 lines (32 loc) · 897 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
# imports
import os.path
import json
class Config:
"""
classe pour gérer le fichier de config
"""
json_file = ""
def __init__(self, fichier_config):
# =================================
Config.json_file = fichier_config
def json_file_exist(self):
# ========================
return os.path.isfile(Config.json_file)
def init(self, config_file):
# ==========================
with open(Config.json_file, 'w') as f:
json.dump(config_file, f)
def load(self, cle):
# ==================
config_file = {}
with open(Config.json_file, 'r') as f:
config_file = json.load(f)
return config_file[cle]
def save(self, cle, valeur):
# ==========================
config_file = {}
with open(Config.json_file, 'r') as f:
config_file = json.load(f)
config_file[cle] = valeur
with open(Config.json_file, 'w') as f:
json.dump(config_file, f)