Reorder Python argparse argument groups
<p>I'm using <code>argparse</code> and I have a custom argument group <code>required arguments</code>. Is there any way to change the order of the argument groups in the help message? I think it is more logical to have the required arguments before optional arguments, but haven't found any documentation or questions to help.</p>

<p>For example, changing this: </p>

<pre><code>usage: foo.py [-h] -i INPUT [-o OUTPUT]

Foo

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                      Output file name

required arguments:
  -i INPUT, --input INPUT
                      Input file name
</code></pre>

<p>to this: </p>

<pre><code>usage: foo.py [-h] -i INPUT [-o OUTPUT]

Foo

required arguments:
  -i INPUT, --input INPUT
                      Input file name

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                      Output file name
</code></pre>

<p>(example taken from <a href="https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments">this question</a>)</p>