Python: how to handle the exceptions of argparse?
<p>I'd like to use my program this way:</p>

<p>pythonScript -f filename</p>

<p>But if I forgot -f, I still want to get the filename.</p>

<p>So I want this "pythonScript filename" also work (->I can get the file name from args.fileName or from handling the exception)</p>

<p>I know this must be easy, I just can not find a way to do it. Anyone can help me out? Thanks</p>

<pre><code>import argparse
parser = argparse.ArgumentParser(prog='PROG')
parser.add_argument('-f', action='store', dest='fileName',
    default = None, type=str, help='The file name')

try:
    args = parser.parse_args()
except:
    print "xxx"
</code></pre>
