You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Class Config takes two arguments, The first is a Schema(https://github.com/keleshev/schema) to secure the model of config,
16
-
the second is the str path of json config file.
17
-
If the second argument didn't take, the default value('./config.json') is used when you call Config Class trying find this file in the same dir file where you call this Class.
15
+
The Class Config takes two arguments, the first is a Schema(https://github.com/keleshev/schema) to secure the model of config, the second is the str path of json config file.
16
+
17
+
If you don't specify the path, the default value('config.json') will be used if one exists in the same dir where the script is running.
18
18
19
19
For example:
20
20
@@ -30,7 +30,7 @@ SCHEMA_CONFIG = {
30
30
},
31
31
"allowed_clients":[
32
32
{
33
-
"ip":str, # <- Here you can use regex to valid the ip format
33
+
"ip":str, # <- Here you can use regex to validate the ip format
34
34
"timeout":int
35
35
}
36
36
]
@@ -73,11 +73,16 @@ except ConfigException as e:
73
73
exit()
74
74
75
75
#to access your config you need just:
76
+
77
+
78
+
fmt = config.core.logging.format #look this, at this point I'm already using the config variable
79
+
dtfmt = config.core.logging.datefmt #here again
80
+
76
81
logging.getLogger(__name__)
77
82
78
83
logging.basicConfig(
79
-
format=config.core.logging.format, #look this, at this point I'm already using the config variable
80
-
datefmt=config.core.logging.datefmt, #here again
84
+
format=fmt,
85
+
datefmt=dtfmt
81
86
level=20
82
87
)
83
88
@@ -89,7 +94,7 @@ for client in config.core.allowed_clients:
89
94
90
95
```
91
96
92
-
After of create the fist obj you don't need to pass the args again, you can instance of Config in other files of your project
97
+
Instanced the first obj, you can instance Config in other files of your project
0 commit comments