Python: print ALL argparse arguments including defaults
<p>I want to log the usage of a python program which uses the argparse module.  Currently, the logger records the command line usage similar to the answer given in <a href="http://stackoverflow.com/questions/8542725/how-can-i-print-all-arguments-passed-to-a-python-script">this post</a>.  However, that only gives the commandline arguments, and not including the defaults set later in argparse (which is the intended use, after all).  Is there a simple way to print ALL the argparse options to create a nice, tidy <code>usage</code> log entry that includes the default values?</p>

<p>It isn't difficult to go into the argparse namespace to fetch each argument by name, but I am hoping that someone has a concise way of extracting the needed info.  </p>

<p>Any direction is appreciated!</p>

<p>I've done something similar in an application, hopefully the below snippets give you what you need. It is the call to vars that gave me a dictionary of all the arguments.</p>

<pre><code>parser = argparse.ArgumentParser(description='Configure')
....
args = parser.parse_args()
......
options = vars(args)
</code></pre>

python logging namespaces argparse sys