argparse: optional argument as flag and variable
<p>I'm writing a program that takes two argument (paths) and as an option <code>-l</code>, witch enables save the log in a log file.</p>

<p>I'm using <code>argparse</code> and create the following argument:</p>

<pre><code>parser.add_argument('-l', '--logfile', 
                    nargs='?', 
                    const='tranfer.log', 
                    default=False,
                    help='save log of the transfer')
</code></pre>

<p>These are the forms of use:</p>

<ol>
<li><code>prog.py path_1 path_2</code>. Nothing special.</li>
<li><code>prog.py -l filename path_1 path_2</code>. Save the log in <code>filename</code> file.</li>
<li><code>prog.py -l path_1 path_2</code>. Save the log the file by default (say, <code>logfile</code>).</li>
</ol>

<p>I have a problem in item 3, because <code>prog.py</code> takes <code>path_1</code> as the filename of the log file. The issue was easily fixed puttin <code>-l</code> option at the end of the line.</p>

<p><code>prog.py path_1 path_2 -l</code></p>

<p>But I was wondering if there's a way of tell <code>argparse</code> to use the last two option as the path files, because I'll be not the only one who use the program.</p>

<p>Path argument were add as follows:</p>

<pre><code>parser.add_argument('left_path', 
                    action='store',
                    help='first path')
parser.add_argument('right_path', 
                    action='store',
                    help='second path')
</code></pre>