Skip to content

Instantly share code, notes, and snippets.

@peace098beat
Created August 11, 2016 05:47
Show Gist options
  • Save peace098beat/b7805da4eeeca5b6fbdfc59bb05f1cc3 to your computer and use it in GitHub Desktop.
Save peace098beat/b7805da4eeeca5b6fbdfc59bb05f1cc3 to your computer and use it in GitHub Desktop.
[Python] Config Parser
def parse_config(config_path):
# Parse Config
# ============
config = ConfigParser.RawConfigParser()
config.read(config_path)
config_dict = dict()
for section in config.sections():
config_dict[section] = dict()
for option in config.options(section):
value = json.loads(config.get(section, option))
config_dict[section][option] = value
return config_dict
if __name__ == '__main__':
config_ini = """
[signal]
ch = "M"
[spectrum]
start_ms = 95
end_ms = 105
window : "hanning"
nfft : 1024
"""
config_dict = parse_config(config_ini)
print config_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment