I have two classes that required app_config (in my case app_config should globally available in all classes within my project).
Class1 required app_config and it provides few more inputs that I need to update again in app_config, like wise in class2.
Later I need to update app_config in both classes 1 and 2.
what is correct method of updating instance variable. Does I am doing correctly or Do I need to consider differently?
import requests
app_config = {
"MaxThreadCount": 10,
"BaseURL": "https://google.com",
"DB": "some db ip"
}
class Class1():
def __init__(self, app_config):
self.app_config = app_config
def get_few_more_configs_in_class1(self):
var1 = requests.get(self.app_config["BaseURL"])
print("get few data")
return {"class-1": "some inputs"}
def set_appconfig(self, app_config):
self.app_config = app_config
class Class2():
def __init__(self, app_config):
self.app_config = app_config
def gather_few_more_configs_in_class2(self, inputs_from_class1):
print("connect to db")
return {"db-inputs": "some more inpus"}
def set_appconfig(self, app_config):
self.app_config = app_config
c1 = Class1(app_config=app_config)
c2 = Class2(app_config=app_config)
class1_inputs = c1.get_few_more_configs_in_class1()
class2_inputs = c2.gather_few_more_configs_in_class2(class1_inputs)
app_config.update(class1_inputs)
app_config.update(class2_inputs)
c1.set_appconfig(app_config=app_config)
c2.set_appconfig(app_config=app_config)