Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / optparse-how-callbacks-called.html
CommitLineData
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-raising-errors-in-callback.html" />
13<link rel="prev" href="optparse-defining-callback-option.html" />
14<link rel="parent" href="optparse-option-callbacks.html" />
15<link rel="next" href="optparse-raising-errors-in-callback.html" />
16<meta name='aesop' content='information' />
17<title>6.21.4.2 How callbacks are called</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.4.1 Defining a callback"
25 href="optparse-defining-callback-option.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.4 Option Callbacks"
28 href="optparse-option-callbacks.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.4.3 Raising errors in"
31 href="optparse-raising-errors-in-callback.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-defining-callback-option.html">6.21.4.1 Defining a callback</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="optparse-option-callbacks.html">6.21.4 Option Callbacks</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="optparse-raising-errors-in-callback.html">6.21.4.3 Raising errors in</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H3><A NAME="SECTION0082142000000000000000"></A><A NAME="optparse-how-callbacks-called"></A>
56<BR>
576.21.4.2 How callbacks are called
58</H3>
59
60<P>
61All callbacks are called as follows:
62<div class="verbatim"><pre>
63func(option, opt_str, value, parser, *args, **kwargs)
64</pre></div>
65
66<P>
67where
68<DL>
69<DT><STRONG><code>option</code></STRONG></DT>
70<DD>is the Option instance that's calling the callback
71</DD>
72<DT><STRONG><code>opt_str</code></STRONG></DT>
73<DD>is the option string seen on the command-line that's triggering the
74callback. (If an abbreviated long option was used, <code>opt_str</code> will
75be the full, canonical option string--e.g. if the user puts
76<code>"-foo"</code> on the command-line as an abbreviation for
77<code>"-foobar"</code>, then <code>opt_str</code> will be <code>"-foobar"</code>.)
78</DD>
79<DT><STRONG><code>value</code></STRONG></DT>
80<DD>is the argument to this option seen on the command-line. <tt class="module">optparse</tt> will
81only expect an argument if <tt class="member">type</tt> is set; the type of <code>value</code>
82will be the type implied by the option's type. If <tt class="member">type</tt> for this
83option is <code>None</code> (no argument expected), then <code>value</code> will be
84<code>None</code>. If <code>nargs</code> &gt; 1, <code>value</code> will be a tuple of values of
85the appropriate type.
86</DD>
87<DT><STRONG><code>parser</code></STRONG></DT>
88<DD>is the OptionParser instance driving the whole thing, mainly
89useful because you can access some other interesting data through
90its instance attributes:
91<DL>
92<DT><STRONG><code>parser.largs</code></STRONG></DT>
93<DD>the current list of leftover arguments, ie. arguments that have
94been consumed but are neither options nor option arguments.
95Feel free to modify <code>parser.largs</code>, e.g. by adding more
96arguments to it. (This list will become <code>args</code>, the second
97return value of <tt class="method">parse_args()</tt>.)
98</DD>
99<DT><STRONG><code>parser.rargs</code></STRONG></DT>
100<DD>the current list of remaining arguments, ie. with <code>opt_str</code> and
101<code>value</code> (if applicable) removed, and only the arguments
102following them still there. Feel free to modify
103<code>parser.rargs</code>, e.g. by consuming more arguments.
104</DD>
105<DT><STRONG><code>parser.values</code></STRONG></DT>
106<DD>the object where option values are by default stored (an
107instance of optparse.OptionValues). This lets callbacks use the
108same mechanism as the rest of <tt class="module">optparse</tt> for storing option values;
109you don't need to mess around with globals or closures. You can
110also access or modify the value(s) of any options already
111encountered on the command-line.
112</DD>
113</DL>
114</DD>
115<DT><STRONG><code>args</code></STRONG></DT>
116<DD>is a tuple of arbitrary positional arguments supplied via the
117<code>callback_args</code> option attribute.
118</DD>
119<DT><STRONG><code>kwargs</code></STRONG></DT>
120<DD>is a dictionary of arbitrary keyword arguments supplied via
121<code>callback_kwargs</code>.
122</DD>
123</DL>
124
125<P>
126
127<DIV CLASS="navigation">
128<div class='online-navigation'>
129<p></p><hr />
130<table align="center" width="100%" cellpadding="0" cellspacing="2">
131<tr>
132<td class='online-navigation'><a rel="prev" title="6.21.4.1 Defining a callback"
133 href="optparse-defining-callback-option.html"><img src='../icons/previous.png'
134 border='0' height='32' alt='Previous Page' width='32' /></A></td>
135<td class='online-navigation'><a rel="parent" title="6.21.4 Option Callbacks"
136 href="optparse-option-callbacks.html"><img src='../icons/up.png'
137 border='0' height='32' alt='Up One Level' width='32' /></A></td>
138<td class='online-navigation'><a rel="next" title="6.21.4.3 Raising errors in"
139 href="optparse-raising-errors-in-callback.html"><img src='../icons/next.png'
140 border='0' height='32' alt='Next Page' width='32' /></A></td>
141<td align="center" width="100%">Python Library Reference</td>
142<td class='online-navigation'><a rel="contents" title="Table of Contents"
143 href="contents.html"><img src='../icons/contents.png'
144 border='0' height='32' alt='Contents' width='32' /></A></td>
145<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
146 border='0' height='32' alt='Module Index' width='32' /></a></td>
147<td class='online-navigation'><a rel="index" title="Index"
148 href="genindex.html"><img src='../icons/index.png'
149 border='0' height='32' alt='Index' width='32' /></A></td>
150</tr></table>
151<div class='online-navigation'>
152<b class="navlabel">Previous:</b>
153<a class="sectref" rel="prev" href="optparse-defining-callback-option.html">6.21.4.1 Defining a callback</A>
154<b class="navlabel">Up:</b>
155<a class="sectref" rel="parent" href="optparse-option-callbacks.html">6.21.4 Option Callbacks</A>
156<b class="navlabel">Next:</b>
157<a class="sectref" rel="next" href="optparse-raising-errors-in-callback.html">6.21.4.3 Raising errors in</A>
158</div>
159</div>
160<hr />
161<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
162</DIV>
163<!--End of Navigation Panel-->
164<ADDRESS>
165See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
166</ADDRESS>
167</BODY>
168</HTML>