On 16.05.2013 08:08, Jussi Piitulainen wrote:
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?

That's what the program does at the moment. However, I'm not quite happy with it. Generally, the user doesn't know what's the default and it would be confusing if 'prog -i 3' doesn't make 'iopt = 3' turn up in the file at the end. There may also be the case when the user (for whatever reason) _wants_ the default in the file.

I think I will try the opposite instead: the program writes the whole set of options to the file. This would produce a complete and consistent configuration which automatically reflects the hierarchy in which the options were set. And the user can sort it out by hand if he wants.

Regards,
Henry

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to