Created
December 22, 2015 08:08
-
-
Save haard/1cdcf7aabb00b794a767 to your computer and use it in GitHub Desktop.
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
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment