-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.py
39 lines (30 loc) · 905 Bytes
/
Config.py
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
import json
conf_file_name = None
save_file_name = None
config_json = None
save_json = {}
def init(filename):
global conf_file_name
global save_file_name
global config_json
global save_json
conf_file_name = filename
save_file_name = filename + ".save.json"
try:
with open(conf_file_name) as f:
config_json = json.load(f)
print("Configuration file", conf_file_name, "load OK")
except FileNotFoundError:
print("Cannot find configuration file:", conf_file_name)
exit(1)
try:
with open(save_file_name) as f:
save_json = json.load(f)
print("Save file", conf_file_name, "load OK")
except FileNotFoundError:
print("No save file for ", conf_file_name)
def save():
global save_json
global save_file_name
with open(save_file_name, "w") as f:
json.dump(save_json, f)