### Navigation

- index
- modules |
- next |
- previous |
- IPython v0.10 documentation »
- The IPython API »

# DPyGetOpt

## Module: `DPyGetOpt`

Inheritance diagram for `IPython.DPyGetOpt`:

DPyGetOpt – Demiurge Python GetOptions Module

This module is modeled after perl’s Getopt::Long module– which is, in turn, modeled after GNU’s extended getopt() function.

Upon instantiation, the option specification should be a sequence (list) of option definitions.

Options that take no arguments should simply contain the name of the option. If a ! is post-pended, the option can be negated by prepending ‘no’; ie ‘debug!’ specifies that -debug and -nodebug should be accepted.

Mandatory arguments to options are specified using a postpended ‘=’ + a type specifier. ‘=s’ specifies a mandatory string argument, ‘=i’ specifies a mandatory integer argument, and ‘=f’ specifies a mandatory real number. In all cases, the ‘=’ can be substituted with ‘:’ to specify that the argument is optional.

Dashes ‘-‘ in option names are allowed.

If an option has the character ‘@’ postpended (after the argumentation specification), it can appear multiple times within each argument list that is processed. The results will be stored in a list.

The option name can actually be a list of names separated by ‘|’ characters; ie– ‘foo|bar|baz=f@’ specifies that all -foo, -bar, and -baz options that appear on within the parsed argument list must have a real number argument and that the accumulated list of values will be available under the name ‘foo’

## Classes

### `ArgumentError`

class `IPython.DPyGetOpt.``ArgumentError`

  Bases: `IPython.DPyGetOpt.Error`

  Exception indicating an error in the arguments passed to DPyGetOpt.processArguments.

  `__init__`()
    x.__init__(...) initializes x; see x.__class__.__doc__ for signature

### `DPyGetOpt`

class `IPython.DPyGetOpt.``DPyGetOpt`(spec=None, terminators=[, '--'])
  `__init__`(spec=None, terminators=[, '--'])

    Declare and intialize instance variables

    Yes, declaration is not necessary... but one of the things I sorely miss from C/Obj-C is the concept of having an interface definition that clearly declares all instance variables and methods without providing any implementation

    > details. it is a useful reference!

    all instance variables are initialized to 0/Null/None of the appropriate type– not even the default value...

  `addOptionConfigurationTuple`(oTuple)
  `addOptionConfigurationTuples`(oTuple)
  `addTerminator`(newTerm)

    Adds newTerm as terminator of option processing.

    Whenever the option processor encounters one of the terminators during option processing, the processing of options terminates immediately, all remaining options are stored in the termValues instance variable and the full name of the terminator is stored in the terminator instance variable.

  `ignoreCase`()
    Returns 1 if the option processor will ignore case when processing options.
  `isPosixCompliant`()
    Returns the value of the posix compliance flag.
  `parseConfiguration`(spec)
  `processArguments`(args=None)

    Processes args, a list of arguments (including options).

    If args is the same as sys.argv, automatically trims the first argument (the executable name/path).

    If an exception is not raised, the argument list was parsed correctly.

    Upon successful completion, the freeValues instance variable will contain all the arguments that were not associated with an option in the order they were encountered. optionValues is a dictionary containing the value of each option– the method valueForOption() can be used to query this dictionary. terminator will contain the argument encountered that terminated option processing (or None, if a terminator was never encountered) and termValues will contain all of the options that appeared after the Terminator (or an empty list).

  `setAllowAbbreviations`(aFlag=1)
    Enables and disables the expansion of abbreviations during option processing.
  `setIgnoreCase`(aFlag=1)
    Enables and disables ignoring case during option processing.
  `setPosixCompliance`(aFlag=0)

    Enables and disables posix compliance.

    When enabled, ‘+’ can be used as an option prefix and free values can be mixed with options.

  `valueForOption`(optionName, defaultValue=None)
    Return the value associated with optionName. If optionName was not encountered during parsing of the arguments, returns the defaultValue (which defaults to None).
  `willAllowAbbreviations`()
    Returns 1 if abbreviated options will be automatically expanded to the non-abbreviated form (instead of causing an unrecognized option error).

### `Error`

class `IPython.DPyGetOpt.``Error`

  Bases: `exceptions.Exception`

  Base class for exceptions in the DPyGetOpt module.

  `__init__`()
    x.__init__(...) initializes x; see x.__class__.__doc__ for signature

### `SpecificationError`

class `IPython.DPyGetOpt.``SpecificationError`

  Bases: `IPython.DPyGetOpt.Error`

  Exception indicating an error with an option specification.

  `__init__`()
    x.__init__(...) initializes x; see x.__class__.__doc__ for signature

### `TerminationError`

class `IPython.DPyGetOpt.``TerminationError`

  Bases: `IPython.DPyGetOpt.Error`

  Exception indicating an error with an option processing terminator.

  `__init__`()
    x.__init__(...) initializes x; see x.__class__.__doc__ for signature

### Navigation

- index
- modules |
- next |
- previous |
- IPython v0.10 documentation »
- The IPython API »