python + argparse - how to get order of optional arguments from command line
<p>I would like to know how to get order of optional argument passed from commandline to argparse</p>

<p>I have image processing class which is able to apply different actions to image - like rotate, crop, resize... </p>

<p>And order in which these actions are applied is often essential (for example: you want to crop image before you resize it)</p>

<p>I have this code:</p>

<pre><code>parser = argparse.ArgumentParser(description='Image processing arguments')

parser.add_argument('source_file', help='source file')
parser.add_argument('target_file', help='target file')

parser.add_argument('-resize', nargs=2, help='resize image', metavar=('WIDTH', 'HEIGHT'))
parser.add_argument('-rotate', nargs=1, help='rotate image', metavar='ANGLE')
parser.add_argument('-crop', nargs=4, help='crop image', metavar=('START_X','START_Y','WIDTH','HEIGHT'))

ar = parser.parse_args()

print ar
</code></pre>

<p>But - no matter in which order I pass parameters to script:</p>

<p><strong>cmd.py test.jpg test2.jpg -crop 10 10 200 200 -resize 450 300</strong></p>

<p><strong>cmd.py test.jpg test2.jpg -resize 450 300 -crop 10 10 200 200</strong></p>

<p>in Namespace items are always in same order (alphabetical I suppose):</p>

<pre><code>Namespace(crop=['10', '10', '200', '200'], resize=['450', '300'], rotate=None, source_file='test.jpg', target_file='test
2.jpg')
</code></pre>

<p>Is there way to order them by position in command line string or to get their index?</p>
