Python config parser to get all the values from a section?

Question:

I want to get all the values from a section using config parser

I used this but it gives only the first value

def ConfigSectionMap(section):
  dict1 = {}
  options = Config.options(section)
  for option in options:
    try:
      dict1[option] = Config.get(section, option)
      if dict1[option] == -1:
        DebugPrint("skip: %s" % option)
    except:
      print("exception on %s!" % option)
      dict1[option] = None
    return dict1


  Config = ConfigParser.ConfigParser()
  Config.read("/etc/harvest.conf")
  print ConfigSectionMap("files").values()
Asked By: Rishabh

||

Answers:

Make it a dict:

dict(Config.items('Section'))
Answered By: Niclas Nilsson

You can make it a list if ordering is important

list(Config.items('Section'))
Answered By: jithu83
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.