Similar to the brief usage string,optparse can also print a version stringfor your program. You have to supply the string as theversionargument to OptionParser:
parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 1.0")
"%prog" is expanded just like it is inusage. Apartfrom that,version can contain anything you like. When you supplyit,optparse automatically adds a--version option to your parser.If it encounters this option on the command line, it expands yourversion string (by replacing"%prog"), prints it to stdout, andexits.
For example, if your script is called/usr/bin/foo:
$ /usr/bin/foo --versionfoo 1.0