[Tutor] How to update only set CLI args?
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Jan 17 09:18:14 EST 2022
On 17/01/2022 14:00, Leam Hall wrote:
> Writing a CLI app in Python 3.10. There's a "defaults" dict, a config file that gets read into a dict, and command line arguments that can be passed in.
>
> defaults = {'table':'people'}
> defaults.update(config)
> defaults.update(vars(args))
>
> The issue is that if an argument is not set on the command line,
> the args.item has a value of "None", which then overwrites any value
> in defaults or config. How do I update just the set args?
Write a loop to test for none values before updating?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list