Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (62 loc) · 2.16 KB
/
Copy pathmain.py
File metadata and controls
67 lines (62 loc) · 2.16 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from CompleteConfig import *
# define your own config
config_dict = {
"std_key": "std_value",
StrKey("str_key"): "str_value",
Key("comment_key", "comment_key_comment"): "comment_value",
Key(StrKey("comment_str_key"), "comment_str_key_comment"): "comment_str_value",
Key("nocomment_key"): "nocomment_value",
"dict_key": {
"dict_std_key": "dict_std_value",
StrKey("dict_str_key"): "dict_str_value",
Key("dict_comment_key", "dict_comment_key_comment"): "dict_comment_value",
Key(StrKey("dict_comment_str_key"), "dict_comment_str_key_comment"): "dict_comment_str_value",
Key("dict_nocomment_key"): "dict_nocomment_value",
"nested_dict_key": {
"nested_dict_std_key": "nested_dict_std_value",
StrKey("nested_dict_str_key"): "nested_dict_str_value",
Key("nested_dict_comment_key", "nested_dict_comment_key_comment"): "nested_dict_comment_value",
Key(StrKey("nested_dict_comment_str_key"), "nested_dict_comment_str_key_comment"): "nested_dict_comment_str_value",
Key("nested_dict_nocomment_key"): "nested_dict_nocomment_value",
},
},
"list_key": [
"list_std_value1",
"list_std_value2",
1,
1.1,
False,
[
"list_std_value3",
"list_std_value4",
2,
2.2,
True,
]
],
"boolean": True,
"integer": 123,
"float": 123.456,
StrKey("dict_str_key"): {
"dict_std_key": "dict_std_value",
},
Key("dict_comment_key", "dict_comment_key_comment"): {
"dict_std_key": "dict_std_value",
},
Key(StrKey("dict_comment_str_key"), "dict_comment_str_key_comment"): {
"dict_std_key": "dict_std_value",
},
}
# and store it to a file
with open("test.conf", "w") as f:
dump(f, config_dict)
# open an existing config
with open("test.conf", "r") as f:
config_dict = load(f)
# change something
config_dict["std_key"] = "new_std_value"
config_dict["dict_str_key"]["dict_std_key"] = "new_dict_std_value"
# and save your changes to the file
with open("test.conf", "w") as f:
dump(f, config_dict)
# Path: main.py