How to print just the content of the help string of a specific argument of ArgParse
<p>Is there a way to access the help strings for specific arguments of the argument parser library object? </p>

<p>I want to print the help string content if the option was present on the command line. <em>Not</em> the complete help text that Argument Parser can display via ArgumentParser.print_help .</p>

<p>So something along those lines:</p>

<pre><code>parser = argparse.ArgumentParser()

parser.add_argument("-d", "--do_x", help='the program will do X')

if do_x:
    print(parser.&lt;WHAT DO I HAVE TO PUT HERE?&gt;('do_x')
</code></pre>

<p>And this is the required behavior</p>

<p>$program -d</p>

<blockquote>
  <p>the program will do X</p>
</blockquote>

<p><code>parser._actions</code> is a list of the <code>Action</code> objects.  You can also grab object when creating the parser.</p>

<pre><code>a=parser.add_argument(...)
...

If args.do_x:
      print a.help
</code></pre>

<p>Play with <code>argparse</code> in an interactive session.  Look at <code>a</code> from such an assignment.</p>

python argparse