I have an yaml file example
logging:
formatter:"abc"
handler:""
network:
type:"udp"
udp:
ip:"12.3.32.0"
port:"20002"
when i start python program, i am passing config.yaml as command line args using argparse module, i am trying to load yaml file as below
main.py
def load_config(self):
parser = argparse.ArgumentParser(description='my yaml script')
parser.add_argument('-f','--filepath', help='yaml file path')
self.args = parser.parse_args()
with open(args.filepath, 'r') as yamlStream:
try:
self.config = yaml.safe_load(yamlStream)
except yaml.YAMLError as exc:
print(exc)
and when i want to ready loggin i am passing
logger.load_config(self.config["logging"])
logger.py
def load_config(self, config):
self.config = config
logging.config.dictConfig(self.config)
but i do not want to load in the beginning when i start main, i want to pass only file path then load blocks of logging, network of yaml config whenever needed.