Website hosting service by Active-Venture.com
  

 Back to Index


6.20.3.4 Option types

optparse supports six option types out of the box: string, int, long, choice, float and complex. (Of these, string, int, float, and choice are the most commonly used --long and complex are there mainly for completeness.) It's easy to add new option types by subclassing the Option class; see section 6.20.5, ``Extending optparse.''

Arguments to string options are not checked or converted in any way: the text on the command line is stored in the destination (or passed to the callback) as-is.

Integer arguments are passed to int() to convert them to Python integers. If int() fails, so will optparse, although with a more useful error message. Internally, optparse raises OptionValueError in optparse.check_builtin(); at a higher level (in OptionParser), optparse catches this exception and terminates your program with a useful error message.

Likewise, float arguments are passed to float() for conversion, long arguments to long(), and complex arguments to complex(). Apart from that, they are handled identically to integer arguments.

Choice options are a subtype of string options. A master list or tuple of choices (strings) must be passed to the option constructor (make_option() or OptionParser.add_option()) as the choices keyword argument. Choice option arguments are compared against this master list in optparse.check_choice(), and OptionValueError is raised if an unknown string is given.

 

  

 

© 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