Created
December 22, 2015 08:08
Revisions
-
haard created this gist
Dec 22, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ from argparse import ArgumentParser from configparser import ConfigParser import pprint def main(): # Read file config fparser = ConfigParser() fparser.read('config.conf') config = {'some.key': 'some_value'} # Hard-coded default for section in fparser.sections(): for key, value in fparser[section].items(): if value is not None: config[section + '.' + key] = value # Read command-line config parser = ArgumentParser() parser.add_argument('--some.key') parser.add_argument('--some.key2') parser.add_argument('--other.key') args = parser.parse_args() for key, value in args.__dict__.items(): if not value is None: config[key] = value return config if __name__ == '__main__': pprint.pprint(main())