Iam totally new to stackoverflow and actually I found a resolution to my excisting problem : Creating a class with all the elements specified in a file using ConfigParser. The given resolution of pillmuncher is nearly perfect in my case. But I need to distinguish the sections and not override everytime the corresponding values.
Is there a way to do the same class but to distuingish sections and therefore names?
Sample input (config file):
[x_axis]
speed = 1020
...
[y_axis]
speed = 1030
...
Class of pillmuncher:
from ConfigParser import SafeConfigParser
section_names = 'x_axis', 'y_axis'
class MyConfiguration(object):
def __init__(self, *file_names):
parser = SafeConfigParser()
parser.optionxform = str # make option names case sensitive
found = parser.read(file_names)
if not found:
raise ValueError('No config file found!')
for name in section_names:
self.__dict__.update(parser.items(name)) # <-- here the magic happens
config = MyConfiguration('my.cfg', 'other.cfg')
Please, even if Iam asking a total noob question, give me an hint in which direction i should look for answers. A global config file, represented with all its sections, should not only be my conercn.