Determine actually given command line arguments

Jussi Piitulainen jpiitula at ling.helsinki.fi
Wed May 15 08:51:37 EDT 2013


Colin J. Williams writes:

> On 15/05/2013 2:34 AM, Henry Leyh wrote:
> > Hello,

> > I am writing a program that gets its parameters from a combination
> > of config file (using configparser) and command line arguments
> > (using argparse).  Now I would also like the program to be able to
> > _write_ a configparser config file that contains only the
> > parameters actually given on the commandline.  Is there a simple
> > way to determine which command line arguments were actually given
> > on the commandline, i.e. does argparse.ArgumentParser() know which
> > of its namespace members were actually hit during parse_args().
> >
> > I have tried giving the arguments default values and then looking
> > for those having a non-default value but this is really awkward,
> > especially if it comes to non-string arguments.  Also, parsing
> > sys.argv looks clumsy because you have to keep track of short and
> > long options with and without argument etc. i.e. all things that I
> > got argparse for in the first place.
> >
> > Thanks && Greetings,
> > Henry

> Try sys.argv

You people should read what you quote, or what you don't quote when
you cut the relevant portion.

Q. ... parsing sys.argv looks clumsy because  ...
A. Try sys.argv

I mean, huh?



More information about the Python-list mailing list