[Tutor] How to update only set CLI args?
Leam Hall
leamhall at gmail.com
Mon Jan 17 21:17:54 EST 2022
On 1/17/22 19:19, Cameron Simpson wrote:
> On 17Jan2022 17:11, Leam Hall <leamhall at gmail.com> wrote:
>> This is what I came up with, after my work day was done. :)
>>
>> ###
>>
>> def sort_args(defaults, config, args):
>> """ Returns dict of configuration, with defaults lowest priority,
>> then config file options, then CLI args as highest.
>> """
>> defaults = copy.deepcopy(defaults)
>> defaults.update(config)
>> for key, value in vars(args).items():
>> if value:
>
> This won't do the right thing if value is eg 0. If you know an omitted
> CLI option will be None (ideally it would not even be present) then do a
> precise check for None, not "falsiness".
>
> if value is not None:
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
That was my goal, but I didn't have the syntax. I had tried:
if value not None:
Code updated, thanks!
Leam
--
Site Automation Programmer (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well (github.com/LeamHall)
More information about the Tutor
mailing list