Determine actually given command line arguments

Colin J. Williams cjw at ncf.ca
Wed May 15 08:03:28 EDT 2013


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

Colin W.



More information about the Python-list mailing list