Monthly Archives: July 2009

Ahh ! for argparse

Its been a while since I blogged . Just a lot happening on the crystallography side of things to allow me the time to blog.

I have also been coding a lot lately and have gotten started with some GUI writing in wxpython.

This post is about trying to get back into the groove by telling you about argparse . Having talked about optparse and command line parsing , I heard about argparse thanks to a talk that I caught  by clicking a link on  the Pycon2009 master schedule .  This link has all the Pycon 2009 slides and video links in one place – a great resource.

For those interested in argparse check out the “Plenary Evening session ” on Sunday Mar 29th 1.20 pm at PyCon2009 where Steven Bethard talks about argparse.

The most important difference between argparse and optparse is that argparse provides better handling for positional arguments in addition to optional arguments . Argparse also provides automatically generated useage information and   takes care of handling cases like when the user forgets to provide any arguments and prints the help information by default.

The key differences are summarized in the excellent documentation at this URL , so I will not rehash it . But I have happily switched over to argparse from optparse and hope argparse becomes part of the python standard libraries soon.

For some code examples check out my github repository especially the script