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? -- http://mail.python.org/mailman/listinfo/python-list