Determine actually given command line arguments
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Thu May 16 02:08:45 EDT 2013
Henry Leyh writes:
> But now I would also like to be able to _write_ such a config file
> FILE that can be read in a later run. And FILE should contain only
> those arguments that were given on the command line.
>
> Say, I tell argparse to look for arguments -s|--sopt STRING,
> -i|--iopt INT, -b|--bopt [BOOL], -C CONFFILE. Then 'prog -s bla -i
> 42 -C cfile' should produce a confparser compatible cfile which
> contains
>
> [my_options]
> sopt = blah
> iopt = 42
>
> and not 'bopt = False' (if False was the program's default for
> bopt).
Could you instead write those options that differ from the defaults?
You could parse an actual command line and an empty command line, and
work out the difference.
So 'prog -i 3' would not cause 'iopt = 3' to be written if 3 is the
default for iopt, but would that be a problem?
More information about the Python-list
mailing list