<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.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=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<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=
"optparse-what-options-for.html" />
<link rel=
"prev" href=
"optparse-background.html" />
<link rel=
"parent" href=
"optparse-background.html" />
<link rel=
"next" href=
"optparse-what-options-for.html" />
<meta name='aesop' content='information'
/>
<title>6.21.1.1 Terminology
</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=
"6.21.1 Background"
href=
"optparse-background.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=
"6.21.1 Background"
href=
"optparse-background.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=
"6.21.1.2 What are options"
href=
"optparse-what-options-for.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></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=
"optparse-background.html">6.21.1 Background
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"optparse-background.html">6.21.1 Background
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"optparse-what-options-for.html">6.21.1.2 What are options
</A>
<!--End of Navigation Panel-->
<H3><A NAME=
"SECTION0082111000000000000000"></A><A NAME=
"optparse-terminology"></A>
<DT><STRONG>argument
</STRONG></DT>
<DD>a string entered on the command-line, and passed by the shell to
<code>execl()
</code> or
<code>execv()
</code>. In Python, arguments are elements of
<code>sys.argv[
1:]
</code> (
<code>sys.argv[
0]
</code> is the name of the program being
executed).
<span class=
"Unix">Unix
</span> shells also use the term ``word''.
It is occasionally desirable to substitute an argument list other
than
<code>sys.argv[
1:]
</code>, so you should read ``argument'' as ``an element of
<code>sys.argv[
1:]
</code>, or of some other list provided as a substitute for
<code>sys.argv[
1:]
</code>''.
<DT><STRONG>option
</STRONG></DT>
<DD>an argument used to supply extra information to guide or customize the
execution of a program. There are many different syntaxes for
options; the traditional
<span class=
"Unix">Unix
</span> syntax is a hyphen (``-'') followed by a
single letter, e.g.
<code>"-x"</code> or
<code>"-F"</code>. Also, traditional
<span class=
"Unix">Unix
</span>
syntax allows multiple options to be merged into a single argument,
e.g.
<code>"-x -F"</code> is equivalent to
<code>"-xF"</code>. The GNU project
introduced
<code>"-"</code> followed by a series of hyphen-separated words,
e.g.
<code>"-file"</code> or
<code>"-dry-run"</code>. These are the only two option
syntaxes provided by
<tt class=
"module">optparse
</tt>.
Some other option syntaxes that the world has seen include:
a hyphen followed by a few letters, e.g.
<code>"-pf"</code> (this is
<em>not
</em> the same as multiple options merged into a single argument)
a hyphen followed by a whole word, e.g.
<code>"-file"</code> (this is
technically equivalent to the previous syntax, but they aren't
usually seen in the same program)
a plus sign followed by a single letter, or a few letters,
or a word, e.g.
<code>"+f"</code>,
<code>"+rgb"</code>
a slash followed by a letter, or a few letters, or a word, e.g.
<code>"/f"</code>,
<code>"/file"</code>
These option syntaxes are not supported by
<tt class=
"module">optparse
</tt>, and they never will
be. This is deliberate: the first three are non-standard on any
environment, and the last only makes sense if you're exclusively
targeting VMS, MS-DOS, and/or Windows.
<DT><STRONG>option argument
</STRONG></DT>
<DD>an argument that follows an option, is closely associated with that
option, and is consumed from the argument list when that option is.
With
<tt class=
"module">optparse
</tt>, option arguments may either be in a separate argument
<div class=
"verbatim"><pre>
or included in the same argument:
<div class=
"verbatim"><pre>
Typically, a given option either takes an argument or it doesn't.
Lots of people want an ``optional option arguments'' feature, meaning
that some options will take an argument if they see it, and won't if
they don't. This is somewhat controversial, because it makes parsing
ambiguous: if
<code>"-a"</code> takes an optional argument and
<code>"-b"</code> is
another option entirely, how do we interpret
<code>"-ab"</code>? Because of
this ambiguity,
<tt class=
"module">optparse
</tt> does not support this feature.
<DT><STRONG>positional argument
</STRONG></DT>
<DD>something leftover in the argument list after options have been
parsed, i.e. after options and their arguments have been parsed and
removed from the argument list.
<DT><STRONG>required option
</STRONG></DT>
<DD>an option that must be supplied on the command-line; note that the
phrase ``required option'' is self-contradictory in English.
<tt class=
"module">optparse
</tt>
doesn't prevent you from implementing required options, but doesn't
give you much help at it either. See
<code>examples/required_1.py
</code> and
<code>examples/required_2.py
</code> in the
<tt class=
"module">optparse
</tt> source distribution for two
ways to implement required options with
<tt class=
"module">optparse
</tt>.
For example, consider this hypothetical command-line:
<div class=
"verbatim"><pre>
prog -v --report /tmp/report.txt foo bar
<code>"-v"</code> and
<code>"-report"</code> are both options. Assuming that
<b class=
"programopt">--report
</b> takes one argument,
<code>"/tmp/report.txt"</code> is an option
argument.
<code>"foo"</code> and
<code>"bar"</code> are positional arguments.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.21.1 Background"
href=
"optparse-background.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=
"6.21.1 Background"
href=
"optparse-background.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=
"6.21.1.2 What are options"
href=
"optparse-what-options-for.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></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=
"optparse-background.html">6.21.1 Background
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"optparse-background.html">6.21.1 Background
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"optparse-what-options-for.html">6.21.1.2 What are options
</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.