#!python3 import tempfile import confparser def parse_test(): msg = '''\ # comment with ":" and "=" in it: := a= Test # another comment with space and := tada b = "Test of a long string" # third comment c=What do YOU want ? '' d = value with a squote at the end ' e = value with a dquote at the end " f = "value with a \\" inside" x.y.z = there you can have a full tree of parameters ''' with tempfile.NamedTemporaryFile(mode='w', encoding='utf8') as f: f.write(msg) print('Following lines have been written to the file:') print('-'*40) print(msg) print('-'*40) f.flush() dic = confparser.read_conf(f.name) print('read dic:', dic) dictest = { 'a': 'Test', 'b': 'Test of a long string', 'c': "What do YOU want ? ''", 'd': 'value with a squote at the end \'', 'e': 'value with a dquote at the end "', 'f': 'value with a " inside', 'x.y.z': 'there you can have a full tree of parameters', } if dic != dictest: a = set(dictest.keys()) b = set(dic.keys()) if a != b: diff = a.difference(b).union(b.difference(a)) raise Exception('not same keys between two dicts:', diff) a = set(dictest.values()) b = set(dic.values()) if a != b: diff = a.difference(b).union(b.difference(a)) raise Exception('differences between two set of values:', diff)