title: How to ConfigParse a file keeping multiple values for identical keys?
body: <p>I need to be able to use the <code>ConfigParser</code> to read multiple values for the same key. Example config file:</p>
  
  <pre><code>[test]
  foo = value1
  foo = value2
  xxx = yyy
  </code></pre>
  
  <p>With the 'standard' use of <code>ConfigParser</code> there will be one key <code>foo</code> with the value <code>value2</code>. But I need the parser to read in both values.</p>
  
  <p>Following an <a href="https://stackoverflow.com/questions/5396144/python-config-parser-duplicate-key-support/5396653#5396653">entry on duplicate key</a> I have created the following example code:</p>
  
  <pre><code>from collections import OrderedDict
  from ConfigParser import RawConfigParser
  
  class OrderedMultisetDict(OrderedDict):
      def __setitem__(self, key, value):
  
          try:
              item = self.__getitem__(key)
          except KeyError:
              super(OrderedMultisetDict, self).__setitem__(key, value)
              return
  
          print "item: ", item, value
          if isinstance(value, list):
              item.extend(value)
          else:
              item.append(value)
          super(OrderedMultisetDict, self).__setitem__(key, item)
  
  
  config = RawConfigParser(dict_type = OrderedDict)
  config.read(["test.cfg"])
  print config.get("test",  "foo")
  print config.get("test",  "xxx")
  
  config2 = RawConfigParser(dict_type = OrderedMultisetDict)
  config2.read(["test.cfg"])
  print config2.get("test",  "foo")
  print config.get("test",  "xxx")
  </code></pre>
  
  <p>The first part (with <code>config</code>) reads in the config file us 'usual', leaving only <code>value2</code> as the value for <code>foo</code> (overwriting/deleting the other value) and I get the following, expected output:</p>
  
  <pre><code>value2
  yyy
  </code></pre>
  
  <p>The second part (<code>config2</code>) uses my approach to append multiple values to a list, but the output instead is </p>
  
  <pre><code>['value1', 'value2', 'value1\nvalue2']
  ['yyy', 'yyy']
  </code></pre>
  
  <p>How do I get rid of the repetitive values? I am expecting an output as follows: </p>
  
  <pre><code>['value1', 'value2']
  yyy
  </code></pre>
  
  <p>or </p>
  
  <pre><code>['value1', 'value2']
  ['yyy']
  </code></pre>
  
  <p>(I don't mind if EVERY value is in a list...). Any suggestions welcome. </p>