<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"dist.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"dist.html" title='Distributing Python Modules'
/>
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-distutils.filelist.html" />
<link rel=
"prev" href=
"module-distutils.errors.html" />
<link rel=
"parent" href=
"api-reference.html" />
<link rel=
"next" href=
"module-distutils.filelist.html" />
<meta name='aesop' content='information'
/>
<title>10.18 distutils.fancy_getopt -- Wrapper around the standard getopt module
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"10.17 distutils.errors "
href=
"module-distutils.errors.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"10. API Reference"
href=
"api-reference.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"10.19 distutils.filelist "
href=
"module-distutils.filelist.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Distributing Python Modules
</td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-distutils.errors.html">10.17 distutils.errors
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"api-reference.html">10. API Reference
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-distutils.filelist.html">10.19 distutils.filelist
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION00101800000000000000000">
10.18 <tt class=
"module">distutils.fancy_getopt
</tt>
-- Wrapper around the standard getopt module
</A>
<A NAME=
"module-distutils.fancygetopt"></A>
This module provides a wrapper around the standard
<tt class=
"module">getopt
</tt>
module that provides the following additional features:
<LI>short and long options are tied together
<LI>options have help strings, so
<tt class=
"function">fancy_getopt
</tt> could potentially
create a complete usage summary
<LI>options set attributes of a passed-in object
<LI>boolean options can have ``negative aliases'' -- eg. if
<b class=
"programopt">--quiet
</b> is the ``negative alias'' of
<b class=
"programopt">--verbose
</b>, then
<b class=
"programopt">--quiet
</b> on the command
line sets
<var>verbose
</var> to false.
<b class=
"du-xxx">Should be replaced with
<tt class=
"module">optik
</tt> (which is also now
known as
<tt class=
"module">optparse
</tt> in Python
2.3 and later).
</b>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
97' xml:id='l2h-
97'
class=
"function">fancy_getopt
</tt></b>(
</nobr></td>
<td><var>options, negative_opt, object, args
</var>)
</td></tr></table></dt>
Wrapper function.
<var>options
</var> is a list of
"<tt class="samp
">(long_option, short_option, help_string)</tt>" 3-tuples as described in the
constructor for
<tt class=
"class">FancyGetopt
</tt>.
<var>negative_opt
</var> should be a dictionary
mapping option names to option names, both the key and value should be in the
<var>options
</var> list.
<var>object
</var> is an object which will be used to store
values (see the
<tt class=
"method">getopt()
</tt> method of the
<tt class=
"class">FancyGetopt
</tt> class).
<var>args
</var> is the argument list. Will use
<code>sys.argv[
1:]
</code> if you
pass
<code>None
</code> as
<var>args
</var>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
98' xml:id='l2h-
98'
class=
"function">wrap_text
</tt></b>(
</nobr></td>
<td><var>text, width
</var>)
</td></tr></table></dt>
Wraps
<var>text
</var> to less than
<var>width
</var> wide.
<span class=
"warning"><b class=
"label">Warning:
</b>
Should be replaced with
<tt class=
"module">textwrap
</tt> (which is available
in Python
2.3 and later).
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
99' xml:id='l2h-
99'
class=
"class">FancyGetopt
</tt></b>(
</nobr></td>
<td><var></var><big>[
</big><var>option_table=
<code>None
</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
The option_table is a list of
3-tuples:
"<tt class="samp
">(long_option,
short_option, help_string)</tt>"
If an option takes an argument, its
<var>long_option
</var> should have
<code>'='
</code>
appended;
<var>short_option
</var> should just be a single character, no
<code>':'
</code>
in any case.
<var>short_option
</var> should be
<code>None
</code> if a
<var>long_option
</var>
doesn't have a corresponding
<var>short_option
</var>. All option tuples must have
The
<tt class=
"class">FancyGetopt
</tt> class provides the following methods:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
100' xml:id='l2h-
100'
class=
"method">getopt
</tt></b>(
</nobr></td>
<td><var></var><big>[
</big><var>args=
<code>None
</code>, object=
<code>None
</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Parse command-line options in args. Store as attributes on
<var>object
</var>.
If
<var>args
</var> is
<code>None
</code> or not supplied, uses
<code>sys.argv[
1:]
</code>. If
<var>object
</var> is
<code>None
</code> or not supplied, creates a new
<tt class=
"class">OptionDummy
</tt>
instance, stores option values there, and returns a tuple
"<tt class="samp
">(args,
object)</tt>". If
<var>object
</var> is supplied, it is modified in place and
<tt class=
"function">getopt()
</tt> just returns
<var>args
</var>; in both cases, the returned
<var>args
</var> is a modified copy of the passed-in
<var>args
</var> list, which
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
101' xml:id='l2h-
101'
class=
"method">get_option_order
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Returns the list of
"<tt class="samp
">(option, value)</tt>" tuples processed by the
previous run of
<tt class=
"method">getopt()
</tt> Raises
<tt class=
"exception">RuntimeError
</tt> if
<tt class=
"method">getopt()
</tt> hasn't been called yet.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
102' xml:id='l2h-
102'
class=
"method">generate_help
</tt></b>(
</nobr></td>
<td><var></var><big>[
</big><var>header=
<code>None
</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Generate help text (a list of strings, one per suggested line of
output) from the option table for this
<tt class=
"class">FancyGetopt
</tt> object.
If supplied, prints the supplied
<var>header
</var> at the top of the help.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"10.17 distutils.errors "
href=
"module-distutils.errors.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"10. API Reference"
href=
"api-reference.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"10.19 distutils.filelist "
href=
"module-distutils.filelist.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Distributing Python Modules
</td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-distutils.errors.html">10.17 distutils.errors
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"api-reference.html">10. API Reference
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-distutils.filelist.html">10.19 distutils.filelist
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.