Didn't know where to ask this question. I have the following class architecture:
import os
from configparser import ConfigParser, ExtendedInterpolation
class MyFancyObject:
def __init__(self, config_file_path):
if config_file_path is None:
self.__config_file_path = os.path.join(os.path.dirname(__file__), 'default_config.ini')
else:
self.__config_file_path = config_file_path
self.__config = ConfigParser(interpolation=ExtendedInterpolation())
self.__variable_a = self.__config.get('my_data', 'a_variable')
self.__variable_b = self.__config.get('my_data', 'b_variable')
self.__variable_c = self.__config.get('my_data', 'c_variable')
self.__variable_d = self.__config.get('my_data', 'd_variable')
...
This object takes upon creation an argument specifying a config file which will be loaded by ConfigParser. If the config file path is not specified, then it looks for one in the same directory as the class file. The config file looks something like this:
[my_data]
a_variable = 1
b_variable = hello
c_variable = world
d_variable = 5.4231
Of course, this is just an example to wrap your head around the problem. My issue is that using this architecture, if the config file gets bigger and bigger then there is a lot of code that gets put into place to set the values of the respective class variables because for each entry in the config .ini file you have to get it from the configparser object and assign it to the class variable.
Is there a nicer, cleaner way to get all of the config file data into their respective class variable?