This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Thermi, joker, paul.j3, rhettinger, terry.reedy, wodny85
Date 2021-09-02.20:55:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630616134.91.0.0106204926696.issue44748@roundup.psfhosted.org>
In-reply-to
Content
> With a config file loaded as part of the program, 
> overwrite the values loaded from the config file 
> if the argument was encountered in the argument vector.

It seems to me that default values can already be used for this purpose:

from argparse import ArgumentParser

config = {'w': 5, 'x': 10, 'y': False, 'z': True}

missing = object()
p = ArgumentParser()
p.add_argument('-x', type=int, default=missing)
p.add_argument('-y', action='store_true', default=missing)
ns = p.parse_args()

# update config for specified values
for parameter, value in vars(ns).items():
    if value is not missing:
        config[parameter] = value

print(config)
History
Date User Action Args
2021-09-02 20:55:34rhettingersetrecipients: + rhettinger, terry.reedy, paul.j3, Thermi, joker, wodny85
2021-09-02 20:55:34rhettingersetmessageid: <1630616134.91.0.0106204926696.issue44748@roundup.psfhosted.org>
2021-09-02 20:55:34rhettingerlinkissue44748 messages
2021-09-02 20:55:34rhettingercreate