On 15 May 2013 13:52, Henry Leyh <[email protected]> wrote: > On 15.05.2013 14:24, Roy Smith wrote: >> >> In article <[email protected]>, >> Henry Leyh <[email protected]> wrote: >> >>> 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 think what you're looking for is sys.argv: >> >> $ cat argv.py >> import sys >> print sys.argv >> >> $ python argv.py foo bar >> ['argv.py', 'foo', 'bar'] > > Thanks, but as I wrote in my first posting I am aware of sys.argv and was > hoping to _avoid_ using it because I'd then have to kind of re-implement a > lot of the stuff already there in argparse, e.g. parsing sys.argv for > short/long options, flag/parameter options etc. > > I was thinking of maybe some sort of flag that argparse sets on those > optional arguments created with add_argument() that are really given on the > command line, i.e. those that it stumbles upon them during parse_args().
I don't know about that but I imagine that you could compare values with their defaults to see which have been changed. Oscar -- http://mail.python.org/mailman/listinfo/python-list
