Website hosting service by Active-Venture.com
  

 Back to Index


6.20.2.5 Print a version number

Similar to the brief usage string, optparse can also print a version string for your program. You have to supply the string, as the version argument to OptionParser:

 

parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 1.0")

version can contain anything you like; %prog is expanded in version just as with usage. When you supply it, optparse automatically adds a --version option to your parser. If it encounters this option on the command line, it expands your version string (by replacing %prog), prints it to stdout, and exits.

For example, if your script is called /usr/bin/foo, a user might do:

 

$ /usr/bin/foo --version
foo 1.0
 

  

 

© 2002-2004 Active-Venture.com Webhosting Service

 

Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to http://python.org/doc/

 

Active-Domain.com offers domain name registration, domain name transfer and domain search services  

Cheap domain registration : Register domain name or buy domain name, including free domain hosting services

 
 

Domain registration : Buy domain name or register domain name from $5.95/year only