Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / tut / node18.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="tut.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="tut.html" title='Python Tutorial' />
8<link rel='contents' href='node2.html' title="Contents" />
9<link rel='index' href='node19.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="node19.html" />
13<link rel="prev" href="node17.html" />
14<link rel="parent" href="tut.html" />
15<link rel="next" href="node19.html" />
16<meta name='aesop' content='information' />
17<title>D. Glossary</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="C. History and License"
25 href="node17.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="Python Tutorial"
28 href="tut.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="Index"
31 href="node19.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 Tutorial</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="node2.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><img src='../icons/blank.png'
38 border='0' height='32' alt='' width='32' /></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="node19.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="node17.html">C. History and License</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="tut.html">Python Tutorial</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="node19.html">Index</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION0018000000000000000000"></A><A NAME="glossary"></A>
56<BR>
57D. Glossary
58</H1>
59
60<P>
61<DL>
62<DD><a id='l2h-37' xml:id='l2h-37'></a>
63</DD>
64<DT><STRONG><code>&gt;<code>&gt;</code>&gt;</code></STRONG></DT>
65<DD>The typical Python prompt of the interactive shell. Often seen for
66code examples that can be tried right away in the interpreter.
67<P>
68<a id='l2h-38' xml:id='l2h-38'></a>
69</DD>
70<DT><STRONG><code>.<code>.</code>.</code></STRONG></DT>
71<DD>The typical Python prompt of the interactive shell when entering code
72for an indented code block.
73
74<P>
75<a id='l2h-39' xml:id='l2h-39'></a>
76</DD>
77<DT><STRONG>BDFL</STRONG></DT>
78<DD>Benevolent Dictator For Life, a.k.a. <a class="ulink" href="http://www.python.org/~guido/"
79 >Guido van
80Rossum</a>, Python's creator.
81
82<P>
83<a id='l2h-40' xml:id='l2h-40'></a>
84</DD>
85<DT><STRONG>byte code</STRONG></DT>
86<DD>The internal representation of a Python program in the interpreter.
87The byte code is also cached in <code>.pyc</code> and <code>.pyo</code>
88files so that executing the same file is faster the second time
89(recompilation from source to byte code can be avoided). This
90``intermediate language'' is said to run on a ``virtual
91machine'' that calls the subroutines corresponding to each bytecode.
92
93<P>
94<a id='l2h-41' xml:id='l2h-41'></a>
95</DD>
96<DT><STRONG>classic class</STRONG></DT>
97<DD>Any class which does not inherit from <tt class="class">object</tt>. See
98<em>new-style class</em>.
99
100<P>
101<a id='l2h-42' xml:id='l2h-42'></a>
102</DD>
103<DT><STRONG>coercion</STRONG></DT>
104<DD>The implicit conversion of an instance of one type to another during an
105operation which involves two arguments of the same type. For example,
106<code>int(3.15)</code> converts the floating point number to the integer
107<code>3</code>, but in <code>3+4.5</code>, each argument is of a different type (one
108int, one float), and both must be converted to the same type before they can
109be added or it will raise a <code>TypeError</code>. Coercion between two
110operands can be performed with the <code>coerce</code> builtin function; thus,
111<code>3+4.5</code> is equivalent to calling <code>operator.add(*coerce(3,
1124.5))</code> and results in <code>operator.add(3.0, 4.5)</code>. Without coercion,
113all arguments of even compatible types would have to be normalized to the
114same value by the programmer, e.g., <code>float(3)+4.5</code> rather than just
115<code>3+4.5</code>.
116
117<P>
118<a id='l2h-43' xml:id='l2h-43'></a>
119</DD>
120<DT><STRONG>complex number</STRONG></DT>
121<DD>An extension of the familiar real number system in which all numbers are
122expressed as a sum of a real part and an imaginary part. Imaginary numbers
123are real multiples of the imaginary unit (the square root of <code>-1</code>),
124often written <code>i</code> in mathematics or <code>j</code> in engineering.
125Python has builtin support for complex numbers, which are written with this
126latter notation; the imaginary part is written with a <code>j</code> suffix,
127e.g., <code>3+1j</code>. To get access to complex equivalents of the
128<tt class="module">math</tt> module, use <tt class="module">cmath</tt>. Use of complex numbers is a
129fairly advanced mathematical feature. If you're not aware of a need for them,
130it's almost certain you can safely ignore them.
131
132<P>
133<a id='l2h-44' xml:id='l2h-44'></a>
134</DD>
135<DT><STRONG>descriptor</STRONG></DT>
136<DD>Any <em>new-style</em> object that defines the methods
137<tt class="method">__get__()</tt>, <tt class="method">__set__()</tt>, or <tt class="method">__delete__()</tt>.
138When a class attribute is a descriptor, its special binding behavior
139is triggered upon attribute lookup. Normally, writing <var>a.b</var> looks
140up the object <var>b</var> in the class dictionary for <var>a</var>, but if
141<var>b</var> is a descriptor, the defined method gets called.
142Understanding descriptors is a key to a deep understanding of Python
143because they are the basis for many features including functions,
144methods, properties, class methods, static methods, and reference to
145super classes.
146
147<P>
148<a id='l2h-45' xml:id='l2h-45'></a>
149</DD>
150<DT><STRONG>dictionary</STRONG></DT>
151<DD>An associative array, where arbitrary keys are mapped to values. The
152use of <tt class="class">dict</tt> much resembles that for <tt class="class">list</tt>, but the keys
153can be any object with a <tt class="method">__hash__()</tt> function, not just
154integers starting from zero. Called a hash in Perl.
155
156<P>
157<a id='l2h-46' xml:id='l2h-46'></a>
158</DD>
159<DT><STRONG>duck-typing</STRONG></DT>
160<DD>Pythonic programming style that determines an object's type by inspection
161of its method or attribute signature rather than by explicit relationship
162to some type object ("If it looks like a duck and quacks like a duck, it
163must be a duck.") By emphasizing interfaces rather than specific types,
164well-designed code improves its flexibility by allowing polymorphic
165substitution. Duck-typing avoids tests using <tt class="function">type()</tt> or
166<tt class="function">isinstance()</tt>. Instead, it typically employs
167<tt class="function">hasattr()</tt> tests or <em>EAFP</em> programming.
168
169<P>
170<a id='l2h-47' xml:id='l2h-47'></a>
171</DD>
172<DT><STRONG>EAFP</STRONG></DT>
173<DD>Easier to ask for forgiveness than permission. This common Python
174coding style assumes the existence of valid keys or attributes and
175catches exceptions if the assumption proves false. This clean and
176fast style is characterized by the presence of many <tt class="keyword">try</tt> and
177<tt class="keyword">except</tt> statements. The technique contrasts with the
178<em>LBYL</em> style that is common in many other languages such as C.
179
180<P>
181<a id='l2h-48' xml:id='l2h-48'></a>
182</DD>
183<DT><STRONG>__future__</STRONG></DT>
184<DD>A pseudo module which programmers can use to enable new language
185features which are not compatible with the current interpreter. For
186example, the expression <code>11/4</code> currently evaluates to <code>2</code>.
187If the module in which it is executed had enabled <em>true division</em>
188by executing:
189
190<P>
191<div class="verbatim"><pre>
192from __future__ import division
193</pre></div>
194
195<P>
196the expression <code>11/4</code> would evaluate to <code>2.75</code>. By
197importing the <a class="ulink" href="../lib/module-future.html"
198 ><tt class="module">__future__</tt></a>
199module and evaluating its variables, you can see when a new feature
200was first added to the language and when it will become the default:
201
202<P>
203<div class="verbatim"><pre>
204&gt;&gt;&gt; import __future__
205&gt;&gt;&gt; __future__.division
206_Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
207</pre></div>
208
209<P>
210<a id='l2h-49' xml:id='l2h-49'></a>
211</DD>
212<DT><STRONG>generator</STRONG></DT>
213<DD>A function that returns an iterator. It looks like a normal function except
214that values are returned to the caller using a <tt class="keyword">yield</tt> statement
215instead of a <tt class="keyword">return</tt> statement. Generator functions often
216contain one or more <tt class="keyword">for</tt> or <tt class="keyword">while</tt> loops that
217<tt class="keyword">yield</tt> elements back to the caller. The function execution is
218stopped at the <tt class="keyword">yield</tt> keyword (returning the result) and is
219resumed there when the next element is requested by calling the
220<tt class="method">next()</tt> method of the returned iterator.
221
222<P>
223<a id='l2h-50' xml:id='l2h-50'></a>
224</DD>
225<DT><STRONG>generator expression</STRONG></DT>
226<DD>An expression that returns a generator. It looks like a normal expression
227followed by a <tt class="keyword">for</tt> expression defining a loop variable, range, and
228an optional <tt class="keyword">if</tt> expression. The combined expression generates
229values for an enclosing function:
230
231<P>
232<div class="verbatim"><pre>
233&gt;&gt;&gt; sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81
234285
235</pre></div>
236
237<P>
238<a id='l2h-51' xml:id='l2h-51'></a>
239</DD>
240<DT><STRONG>GIL</STRONG></DT>
241<DD>See <em>global interpreter lock</em>.
242
243<P>
244<a id='l2h-52' xml:id='l2h-52'></a>
245</DD>
246<DT><STRONG>global interpreter lock</STRONG></DT>
247<DD>The lock used by Python threads to assure that only one thread can be
248run at a time. This simplifies Python by assuring that no two
249processes can access the same memory at the same time. Locking the
250entire interpreter makes it easier for the interpreter to be
251multi-threaded, at the expense of some parallelism on multi-processor
252machines. Efforts have been made in the past to create a
253``free-threaded'' interpreter (one which locks shared data at a much
254finer granularity), but performance suffered in the common
255single-processor case.
256
257<P>
258<a id='l2h-53' xml:id='l2h-53'></a>
259</DD>
260<DT><STRONG>IDLE</STRONG></DT>
261<DD>An Integrated Development Environment for Python. IDLE is a
262basic editor and interpreter environment that ships with the standard
263distribution of Python. Good for beginners, it also serves as clear
264example code for those wanting to implement a moderately
265sophisticated, multi-platform GUI application.
266
267<P>
268<a id='l2h-54' xml:id='l2h-54'></a>
269</DD>
270<DT><STRONG>immutable</STRONG></DT>
271<DD>An object with fixed value. Immutable objects are numbers, strings or
272tuples (and more). Such an object cannot be altered. A new object
273has to be created if a different value has to be stored. They play an
274important role in places where a constant hash value is needed, for
275example as a key in a dictionary.
276
277<P>
278<a id='l2h-55' xml:id='l2h-55'></a>
279</DD>
280<DT><STRONG>integer division</STRONG></DT>
281<DD>Mathematical division discarding any remainder. For example, the
282expression <code>11/4</code> currently evaluates to <code>2</code> in contrast
283to the <code>2.75</code> returned by float division. Also called
284<em>floor division</em>. When dividing two integers the outcome will
285always be another integer (having the floor function applied to it).
286However, if one of the operands is another numeric type (such as a
287<tt class="class">float</tt>), the result will be coerced (see <em>coercion</em>) to
288a common type. For example, an integer divided by a float will result
289in a float value, possibly with a decimal fraction. Integer division
290can be forced by using the <code>//</code> operator instead of the <code>/</code>
291operator. See also <em>__future__</em>.
292
293<P>
294<a id='l2h-56' xml:id='l2h-56'></a>
295</DD>
296<DT><STRONG>interactive</STRONG></DT>
297<DD>Python has an interactive interpreter which means that you can try out
298things and immediately see their results. Just launch <code>python</code> with no
299arguments (possibly by selecting it from your computer's main menu).
300It is a very powerful way to test out new ideas or inspect modules and
301packages (remember <code>help(x)</code>).
302
303<P>
304<a id='l2h-57' xml:id='l2h-57'></a>
305</DD>
306<DT><STRONG>interpreted</STRONG></DT>
307<DD>Python is an interpreted language, as opposed to a compiled one. This means
308that the source files can be run directly without first creating an
309executable which is then run. Interpreted languages typically have a
310shorter development/debug cycle than compiled ones, though their programs
311generally also run more slowly. See also <em>interactive</em>.
312
313<P>
314<a id='l2h-58' xml:id='l2h-58'></a>
315</DD>
316<DT><STRONG>iterable</STRONG></DT>
317<DD>A container object capable of returning its members one at a time.
318Examples of iterables include all sequence types (such as <tt class="class">list</tt>,
319<tt class="class">str</tt>, and <tt class="class">tuple</tt>) and some non-sequence types like
320<tt class="class">dict</tt> and <tt class="class">file</tt> and objects of any classes you define
321with an <tt class="method">__iter__()</tt> or <tt class="method">__getitem__()</tt> method. Iterables
322can be used in a <tt class="keyword">for</tt> loop and in many other places where a
323sequence is needed (<tt class="function">zip()</tt>, <tt class="function">map()</tt>, ...). When an
324iterable object is passed as an argument to the builtin function
325<tt class="function">iter()</tt>, it returns an iterator for the object. This
326iterator is good for one pass over the set of values. When using
327iterables, it is usually not necessary to call <tt class="function">iter()</tt> or
328deal with iterator objects yourself. The <code>for</code> statement does
329that automatically for you, creating a temporary unnamed variable to
330hold the iterator for the duration of the loop. See also
331<em>iterator</em>, <em>sequence</em>, and <em>generator</em>.
332
333<P>
334<a id='l2h-59' xml:id='l2h-59'></a>
335</DD>
336<DT><STRONG>iterator</STRONG></DT>
337<DD>An object representing a stream of data. Repeated calls to the
338iterator's <tt class="method">next()</tt> method return successive items in the
339stream. When no more data is available a <tt class="exception">StopIteration</tt>
340exception is raised instead. At this point, the iterator object is
341exhausted and any further calls to its <tt class="method">next()</tt> method just
342raise <tt class="exception">StopIteration</tt> again. Iterators are required to have
343an <tt class="method">__iter__()</tt> method that returns the iterator object
344itself so every iterator is also iterable and may be used in most
345places where other iterables are accepted. One notable exception is
346code that attempts multiple iteration passes. A container object
347(such as a <tt class="class">list</tt>) produces a fresh new iterator each time you
348pass it to the <tt class="function">iter()</tt> function or use it in a
349<tt class="keyword">for</tt> loop. Attempting this with an iterator will just
350return the same exhausted iterator object used in the previous iteration
351pass, making it appear like an empty container.
352
353<P>
354<a id='l2h-60' xml:id='l2h-60'></a>
355</DD>
356<DT><STRONG>LBYL</STRONG></DT>
357<DD>Look before you leap. This coding style explicitly tests for
358pre-conditions before making calls or lookups. This style contrasts
359with the <em>EAFP</em> approach and is characterized by the presence of
360many <tt class="keyword">if</tt> statements.
361
362<P>
363<a id='l2h-61' xml:id='l2h-61'></a>
364</DD>
365<DT><STRONG>list comprehension</STRONG></DT>
366<DD>A compact way to process all or a subset of elements in a sequence and
367return a list with the results. <code>result = ["0x%02x"
368% x for x in range(256) if x % 2 == 0]</code> generates a list of strings
369containing hex numbers (0x..) that are even and in the range from 0 to 255.
370The <tt class="keyword">if</tt> clause is optional. If omitted, all elements in
371<code>range(256)</code> are processed.
372
373<P>
374<a id='l2h-62' xml:id='l2h-62'></a>
375</DD>
376<DT><STRONG>mapping</STRONG></DT>
377<DD>A container object (such as <tt class="class">dict</tt>) that supports arbitrary key
378lookups using the special method <tt class="method">__getitem__()</tt>.
379
380<P>
381<a id='l2h-63' xml:id='l2h-63'></a>
382</DD>
383<DT><STRONG>metaclass</STRONG></DT>
384<DD>The class of a class. Class definitions create a class name, a class
385dictionary, and a list of base classes. The metaclass is responsible
386for taking those three arguments and creating the class. Most object
387oriented programming languages provide a default implementation. What
388makes Python special is that it is possible to create custom
389metaclasses. Most users never need this tool, but when the need
390arises, metaclasses can provide powerful, elegant solutions. They
391have been used for logging attribute access, adding thread-safety,
392tracking object creation, implementing singletons, and many other
393tasks.
394
395<P>
396<a id='l2h-64' xml:id='l2h-64'></a>
397</DD>
398<DT><STRONG>mutable</STRONG></DT>
399<DD>Mutable objects can change their value but keep their <tt class="function">id()</tt>.
400See also <em>immutable</em>.
401
402<P>
403<a id='l2h-65' xml:id='l2h-65'></a>
404</DD>
405<DT><STRONG>namespace</STRONG></DT>
406<DD>The place where a variable is stored. Namespaces are implemented as
407dictionaries. There are the local, global and builtin namespaces
408as well as nested namespaces in objects (in methods). Namespaces support
409modularity by preventing naming conflicts. For instance, the
410functions <tt class="function">__builtin__.open()</tt> and <tt class="function">os.open()</tt> are
411distinguished by their namespaces. Namespaces also aid readability
412and maintainability by making it clear which module implements a
413function. For instance, writing <tt class="function">random.seed()</tt> or
414<tt class="function">itertools.izip()</tt> makes it clear that those functions are
415implemented by the <a class="ulink" href="../lib/module-random.html"
416 ><tt class="module">random</tt></a>
417and <a class="ulink" href="../lib/module-itertools.html"
418 ><tt class="module">itertools</tt></a> modules
419respectively.
420
421<P>
422<a id='l2h-66' xml:id='l2h-66'></a>
423</DD>
424<DT><STRONG>nested scope</STRONG></DT>
425<DD>The ability to refer to a variable in an enclosing definition. For
426instance, a function defined inside another function can refer to
427variables in the outer function. Note that nested scopes work only
428for reference and not for assignment which will always write to the
429innermost scope. In contrast, local variables both read and write in
430the innermost scope. Likewise, global variables read and write to the
431global namespace.
432
433<P>
434<a id='l2h-67' xml:id='l2h-67'></a>
435</DD>
436<DT><STRONG>new-style class</STRONG></DT>
437<DD>Any class that inherits from <tt class="class">object</tt>. This includes all
438built-in types like <tt class="class">list</tt> and <tt class="class">dict</tt>. Only new-style
439classes can use Python's newer, versatile features like
440<tt class="method">__slots__</tt>, descriptors, properties,
441<tt class="method">__getattribute__()</tt>, class methods, and static methods.
442
443<P>
444<a id='l2h-68' xml:id='l2h-68'></a>
445</DD>
446<DT><STRONG>Python3000</STRONG></DT>
447<DD>A mythical python release, not required to be backward compatible, with
448telepathic interface.
449
450<P>
451<a id='l2h-69' xml:id='l2h-69'></a>
452</DD>
453<DT><STRONG>__slots__</STRONG></DT>
454<DD>A declaration inside a <em>new-style class</em> that saves memory by
455pre-declaring space for instance attributes and eliminating instance
456dictionaries. Though popular, the technique is somewhat tricky to get
457right and is best reserved for rare cases where there are large
458numbers of instances in a memory-critical application.
459
460<P>
461<a id='l2h-70' xml:id='l2h-70'></a>
462</DD>
463<DT><STRONG>sequence</STRONG></DT>
464<DD>An <em>iterable</em> which supports efficient element access using
465integer indices via the <tt class="method">__getitem__()</tt> and
466<tt class="method">__len__()</tt> special methods. Some built-in sequence types
467are <tt class="class">list</tt>, <tt class="class">str</tt>, <tt class="class">tuple</tt>, and <tt class="class">unicode</tt>.
468Note that <tt class="class">dict</tt> also supports <tt class="method">__getitem__()</tt> and
469<tt class="method">__len__()</tt>, but is considered a mapping rather than a
470sequence because the lookups use arbitrary <em>immutable</em> keys
471rather than integers.
472
473<P>
474<a id='l2h-71' xml:id='l2h-71'></a>
475</DD>
476<DT><STRONG>Zen of Python</STRONG></DT>
477<DD>Listing of Python design principles and philosophies that are helpful
478in understanding and using the language. The listing can be found by
479typing ``<code>import this</code>'' at the interactive prompt.
480
481<P>
482</DD>
483</DL>
484
485<P>
486
487<DIV CLASS="navigation">
488<div class='online-navigation'>
489<p></p><hr />
490<table align="center" width="100%" cellpadding="0" cellspacing="2">
491<tr>
492<td class='online-navigation'><a rel="prev" title="C. History and License"
493 href="node17.html"><img src='../icons/previous.png'
494 border='0' height='32' alt='Previous Page' width='32' /></A></td>
495<td class='online-navigation'><a rel="parent" title="Python Tutorial"
496 href="tut.html"><img src='../icons/up.png'
497 border='0' height='32' alt='Up One Level' width='32' /></A></td>
498<td class='online-navigation'><a rel="next" title="Index"
499 href="node19.html"><img src='../icons/next.png'
500 border='0' height='32' alt='Next Page' width='32' /></A></td>
501<td align="center" width="100%">Python Tutorial</td>
502<td class='online-navigation'><a rel="contents" title="Table of Contents"
503 href="node2.html"><img src='../icons/contents.png'
504 border='0' height='32' alt='Contents' width='32' /></A></td>
505<td class='online-navigation'><img src='../icons/blank.png'
506 border='0' height='32' alt='' width='32' /></td>
507<td class='online-navigation'><a rel="index" title="Index"
508 href="node19.html"><img src='../icons/index.png'
509 border='0' height='32' alt='Index' width='32' /></A></td>
510</tr></table>
511<div class='online-navigation'>
512<b class="navlabel">Previous:</b>
513<a class="sectref" rel="prev" href="node17.html">C. History and License</A>
514<b class="navlabel">Up:</b>
515<a class="sectref" rel="parent" href="tut.html">Python Tutorial</A>
516<b class="navlabel">Next:</b>
517<a class="sectref" rel="next" href="node19.html">Index</A>
518</div>
519</div>
520<hr />
521<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
522</DIV>
523<!--End of Navigation Panel-->
524<ADDRESS>
525See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
526</ADDRESS>
527</BODY>
528</HTML>