When I used to teach Python, I would always get on students to use Python’s built-in optparse module when writing scripts. For whatever NIH reason, people wanted to do a half-ass job of groveling over sys.argv
instead of using a module specifically designed to alleviate the pain.
Things on the command line parsing front have been advancing lately. To wit, the new argparse module:
The argparse module was added to Python 2.7 as a replacement for optparse. The implementation of argparse supports features that would not have been easy to add to optparse, and that would have required backwards-incompatible API changes, so a new module was brought into the library instead. optparse is still supported, but is not likely to receive new features.
This makes a must read out of Doug Hellmann’s Python Module of the Week (PyMOTW) entry for argparse to get a good basic understanding of the module.