Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="optparse-what-options-for.html" /> | |
13 | <link rel="prev" href="optparse-background.html" /> | |
14 | <link rel="parent" href="optparse-background.html" /> | |
15 | <link rel="next" href="optparse-what-options-for.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.21.1.1 Terminology</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.21.1 Background" | |
25 | href="optparse-background.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6.21.1 Background" | |
28 | href="optparse-background.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.21.1.2 What are options" | |
31 | href="optparse-what-options-for.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="optparse-background.html">6.21.1 Background</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="optparse-background.html">6.21.1 Background</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="optparse-what-options-for.html">6.21.1.2 What are options</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H3><A NAME="SECTION0082111000000000000000"></A><A NAME="optparse-terminology"></A> | |
56 | <BR> | |
57 | 6.21.1.1 Terminology | |
58 | </H3> | |
59 | <DL> | |
60 | <DT><STRONG>argument</STRONG></DT> | |
61 | <DD>a string entered on the command-line, and passed by the shell to | |
62 | <code>execl()</code> or <code>execv()</code>. In Python, arguments are elements of | |
63 | <code>sys.argv[1:]</code> (<code>sys.argv[0]</code> is the name of the program being | |
64 | executed). <span class="Unix">Unix</span> shells also use the term ``word''. | |
65 | ||
66 | <P> | |
67 | It is occasionally desirable to substitute an argument list other | |
68 | than <code>sys.argv[1:]</code>, so you should read ``argument'' as ``an element of | |
69 | <code>sys.argv[1:]</code>, or of some other list provided as a substitute for | |
70 | <code>sys.argv[1:]</code>''. | |
71 | </DD> | |
72 | <DT><STRONG>option </STRONG></DT> | |
73 | <DD>an argument used to supply extra information to guide or customize the | |
74 | execution of a program. There are many different syntaxes for | |
75 | options; the traditional <span class="Unix">Unix</span> syntax is a hyphen (``-'') followed by a | |
76 | single letter, e.g. <code>"-x"</code> or <code>"-F"</code>. Also, traditional <span class="Unix">Unix</span> | |
77 | syntax allows multiple options to be merged into a single argument, | |
78 | e.g. <code>"-x -F"</code> is equivalent to <code>"-xF"</code>. The GNU project | |
79 | introduced <code>"-"</code> followed by a series of hyphen-separated words, | |
80 | e.g. <code>"-file"</code> or <code>"-dry-run"</code>. These are the only two option | |
81 | syntaxes provided by <tt class="module">optparse</tt>. | |
82 | ||
83 | <P> | |
84 | Some other option syntaxes that the world has seen include: | |
85 | ||
86 | <UL> | |
87 | <LI> | |
88 | a hyphen followed by a few letters, e.g. <code>"-pf"</code> (this is | |
89 | <em>not</em> the same as multiple options merged into a single argument) | |
90 | ||
91 | <P> | |
92 | </LI> | |
93 | <LI> | |
94 | a hyphen followed by a whole word, e.g. <code>"-file"</code> (this is | |
95 | technically equivalent to the previous syntax, but they aren't | |
96 | usually seen in the same program) | |
97 | ||
98 | <P> | |
99 | </LI> | |
100 | <LI> | |
101 | a plus sign followed by a single letter, or a few letters, | |
102 | or a word, e.g. <code>"+f"</code>, <code>"+rgb"</code> | |
103 | ||
104 | <P> | |
105 | </LI> | |
106 | <LI> | |
107 | a slash followed by a letter, or a few letters, or a word, e.g. | |
108 | <code>"/f"</code>, <code>"/file"</code> | |
109 | ||
110 | <P> | |
111 | </LI> | |
112 | </UL> | |
113 | ||
114 | <P> | |
115 | These option syntaxes are not supported by <tt class="module">optparse</tt>, and they never will | |
116 | be. This is deliberate: the first three are non-standard on any | |
117 | environment, and the last only makes sense if you're exclusively | |
118 | targeting VMS, MS-DOS, and/or Windows. | |
119 | </DD> | |
120 | <DT><STRONG>option argument</STRONG></DT> | |
121 | <DD>an argument that follows an option, is closely associated with that | |
122 | option, and is consumed from the argument list when that option is. | |
123 | With <tt class="module">optparse</tt>, option arguments may either be in a separate argument | |
124 | from their option: | |
125 | <div class="verbatim"><pre> | |
126 | -f foo | |
127 | --file foo | |
128 | </pre></div> | |
129 | ||
130 | <P> | |
131 | or included in the same argument: | |
132 | <div class="verbatim"><pre> | |
133 | -ffoo | |
134 | --file=foo | |
135 | </pre></div> | |
136 | ||
137 | <P> | |
138 | Typically, a given option either takes an argument or it doesn't. | |
139 | Lots of people want an ``optional option arguments'' feature, meaning | |
140 | that some options will take an argument if they see it, and won't if | |
141 | they don't. This is somewhat controversial, because it makes parsing | |
142 | ambiguous: if <code>"-a"</code> takes an optional argument and <code>"-b"</code> is | |
143 | another option entirely, how do we interpret <code>"-ab"</code>? Because of | |
144 | this ambiguity, <tt class="module">optparse</tt> does not support this feature. | |
145 | </DD> | |
146 | <DT><STRONG>positional argument</STRONG></DT> | |
147 | <DD>something leftover in the argument list after options have been | |
148 | parsed, i.e. after options and their arguments have been parsed and | |
149 | removed from the argument list. | |
150 | </DD> | |
151 | <DT><STRONG>required option</STRONG></DT> | |
152 | <DD>an option that must be supplied on the command-line; note that the | |
153 | phrase ``required option'' is self-contradictory in English. <tt class="module">optparse</tt> | |
154 | doesn't prevent you from implementing required options, but doesn't | |
155 | give you much help at it either. See <code>examples/required_1.py</code> and | |
156 | <code>examples/required_2.py</code> in the <tt class="module">optparse</tt> source distribution for two | |
157 | ways to implement required options with <tt class="module">optparse</tt>. | |
158 | </DD> | |
159 | </DL> | |
160 | ||
161 | <P> | |
162 | For example, consider this hypothetical command-line: | |
163 | <div class="verbatim"><pre> | |
164 | prog -v --report /tmp/report.txt foo bar | |
165 | </pre></div> | |
166 | ||
167 | <P> | |
168 | <code>"-v"</code> and <code>"-report"</code> are both options. Assuming that | |
169 | <b class="programopt">--report</b> takes one argument, <code>"/tmp/report.txt"</code> is an option | |
170 | argument. <code>"foo"</code> and <code>"bar"</code> are positional arguments. | |
171 | ||
172 | <P> | |
173 | ||
174 | <DIV CLASS="navigation"> | |
175 | <div class='online-navigation'> | |
176 | <p></p><hr /> | |
177 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
178 | <tr> | |
179 | <td class='online-navigation'><a rel="prev" title="6.21.1 Background" | |
180 | href="optparse-background.html"><img src='../icons/previous.png' | |
181 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
182 | <td class='online-navigation'><a rel="parent" title="6.21.1 Background" | |
183 | href="optparse-background.html"><img src='../icons/up.png' | |
184 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
185 | <td class='online-navigation'><a rel="next" title="6.21.1.2 What are options" | |
186 | href="optparse-what-options-for.html"><img src='../icons/next.png' | |
187 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
188 | <td align="center" width="100%">Python Library Reference</td> | |
189 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
190 | href="contents.html"><img src='../icons/contents.png' | |
191 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
192 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
193 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
194 | <td class='online-navigation'><a rel="index" title="Index" | |
195 | href="genindex.html"><img src='../icons/index.png' | |
196 | border='0' height='32' alt='Index' width='32' /></A></td> | |
197 | </tr></table> | |
198 | <div class='online-navigation'> | |
199 | <b class="navlabel">Previous:</b> | |
200 | <a class="sectref" rel="prev" href="optparse-background.html">6.21.1 Background</A> | |
201 | <b class="navlabel">Up:</b> | |
202 | <a class="sectref" rel="parent" href="optparse-background.html">6.21.1 Background</A> | |
203 | <b class="navlabel">Next:</b> | |
204 | <a class="sectref" rel="next" href="optparse-what-options-for.html">6.21.1.2 What are options</A> | |
205 | </div> | |
206 | </div> | |
207 | <hr /> | |
208 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
209 | </DIV> | |
210 | <!--End of Navigation Panel--> | |
211 | <ADDRESS> | |
212 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
213 | </ADDRESS> | |
214 | </BODY> | |
215 | </HTML> |