Создание класса со всеми элементами, указанными в файле, с помощью ConfigParser

Я создал .ini-подобный файл со всеми значениями, которые мне понадобятся позже в моей программе, см. Ниже:

[debugging]
checkForAbort = 10
...

[official]
checkForAbort = 30
...

Я хотел бы прочитать все эти элементы в одном классе и сделать его доступным из других частей моего проекта на Python. То, что у меня есть, это код ниже:

from ConfigParser import SafeConfigParser
import glob

class ConfigurationParameters
    def __init__(self):
        self.checkForAbortDuringIdleTime = None     

    parser = SafeConfigParser()

    # making a list here in case we have multiple files in the future!
    candidatesConfiguration = ['my.cfg']
    foundCandidates = parser.read(candidatesConfiguration)
    missingCandidates = set(candidatesConfiguration) - set(found)
    if foundCandidates:
        print 'Found config files:', sorted(found)
    else
        print 'Missing files     :', sorted(missing)
        print "aborting..."


    # check for mandatory sections below
    for candidateSections in ['official', 'debugging']:
        if not parser.has_section(candidateSections)
            print "the mandatory section", candidateSections " is missing"
            print "aborting..."

    for sectionName in ['official', 'debugging']:
        for name, value in parser.items(section_name):
            self.name = value

Я новичок в Python, но я все еще вижу много проблем с моим кодом:

I am forced to add a attribute for each item in my class file. and keep the configuration file and my class in sync all the time. This class is not a singleton, therefore the reading/parsing will be done from wherever it is imported! If a value is added to the config-file with is not defined in my class, it will probably crash!

Как мне решить эту проблему вместо этого? Могут ли атрибуты класса создаваться динамически?

Моему классу нужно только читать значения, поэтому запись в файл конфигурации не требуется!

Ответы на вопрос(3)

Ваш ответ на вопрос