Created
August 11, 2016 05:47
-
-
Save peace098beat/b7805da4eeeca5b6fbdfc59bb05f1cc3 to your computer and use it in GitHub Desktop.
[Python] Config Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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