refactor: use config and logger in service
This commit is contained in:
24
src/utils/config.py
Normal file
24
src/utils/config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import configparser
|
||||
|
||||
config = None
|
||||
|
||||
def init(config_file: str):
|
||||
global config
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_file)
|
||||
|
||||
def get_instance() -> configparser.ConfigParser:
|
||||
return config
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 本文件的绝对路径
|
||||
import os
|
||||
config_file = os.path.join(os.path.dirname(__file__), "../../configuration/test_conf.ini")
|
||||
init(config_file)
|
||||
conf = get_instance()
|
||||
print(conf.sections())
|
||||
for section in conf.sections():
|
||||
print(conf.options(section))
|
||||
for option in conf.options(section):
|
||||
print(f"{section}.{option}={conf.get(section, option)}")
|
||||
Reference in New Issue
Block a user