|
| 1 | +\chapter{Glossary\label{glossary}} |
| 2 | + |
| 3 | +%%% keep the entries sorted and include at least one \index{} item for each |
| 4 | + |
| 5 | +\begin{description} |
| 6 | + |
| 7 | +\index{...} |
| 8 | +\item[...]{The typical Python prompt of the interactive shell when entering |
| 9 | +code for an indented code block.} |
| 10 | + |
| 11 | +\index{>>>} |
| 12 | +\item[>>>]{The typical Python prompt of the interactive shell. Often seen |
| 13 | +for code examples that can be tried right away in the interpreter.} |
| 14 | + |
| 15 | +\index{__slots__} |
| 16 | +\item[__slots__]{A declaration inside a new-style class that saves |
| 17 | +memory by pre-declaring space for instance attributes and eliminating |
| 18 | +instance dictionaries. Though popular, the technique is somewhat tricky to |
| 19 | +get right and is best reserved for rare cases where there are large numbers |
| 20 | +of instances in a memory critical application.} |
| 21 | + |
| 22 | +\index{BDFL} |
| 23 | +\item[BDFL]{Benevolent Dictator For Life, a.k.a. \ulink{Guido van |
| 24 | +Rossum}{http://www.python.org/~guido/}, Python's creator.} |
| 25 | + |
| 26 | +\index{byte code} |
| 27 | +\item[byte code]{The internal represenatation of a Python program in the |
| 28 | +interpreter. The byte code is also cached in the \code{.pyc} and |
| 29 | +{}\code{.pyo} files so that executing the same file is faster the second |
| 30 | +time (compilation from source to byte code can be saved). This |
| 31 | +"intermediate language" is said to run on a "virtual machine" that calls the |
| 32 | +subroutines corresponding to each bytecode.} |
| 33 | + |
| 34 | +\index{classic class} |
| 35 | +\item[classic class]{Any class which does not inherit from \class{object}. |
| 36 | +See new-style class.} |
| 37 | + |
| 38 | +\index{coercion} |
| 39 | +\item[coercion]{Converting data from one type to another. For example, |
| 40 | +int(3.15) coerces the floating point number to the integer, 3. Most |
| 41 | +mathematical operations have rules for coercing their arguments to a common |
| 42 | +type. For instance, adding 3 + 4.5, causes the integer 3 to be coerced to |
| 43 | +be a float (3.0) before adding to 4.5 resulting in the float 7.5.} |
| 44 | + |
| 45 | +\index{descriptor} |
| 46 | +\item[descriptor]{Any object that defines the methods __get__(), __set__(), |
| 47 | +or __delete__(). When a class attribute is a descriptor, its special |
| 48 | +binding behavior is triggered upon attribute lookup. Normally, writing |
| 49 | +{}\var{a.b} looks up the object \var{b} in the class dictionary for \var{a}, |
| 50 | +but if \var{b} is a descriptor, the defined method gets called. |
| 51 | +Understanding descriptors is a key to a deep understanding of Python because |
| 52 | +they are the basis for many features including functions, |
| 53 | +methods,properties, class methods, static methods, and reference to super |
| 54 | +classes.} |
| 55 | + |
| 56 | +\index{dictionary} |
| 57 | +\item[dictionary]{An associative array, where arbitrary keys are mapped to |
| 58 | +values. The use of `dict` much resembles that for `list`, but the keys can |
| 59 | +be any object with a `__hash__` function, not just integers starting from |
| 60 | +zero. Called a hash in Perl.} |
| 61 | + |
| 62 | +\index{EAFP} |
| 63 | +\item[EAFP]{Easier to ask for forgiveness than permission. This common |
| 64 | +Python coding style assumes the existance of valid keys or attributes and |
| 65 | +catches exceptions if the assumption proves false. This clean and fast |
| 66 | +style is characterized by the presence of many `try` and `except` statments. |
| 67 | +The technique contrasts with the '''LBYL''' style that is common in many |
| 68 | +other languages such as C.} |
| 69 | + |
| 70 | +\index{__future__} |
| 71 | +\item[__future__]{A pseudo module which programmers can use to enable |
| 72 | +new language features which are not compatible with the current interpreter. |
| 73 | +For example, the expression \code{11 / 4} currently evaluates to \code{2}. |
| 74 | +If the module in which it is executed had enabled ``true division`` by |
| 75 | +executing} |
| 76 | +
|
| 77 | +\begin{verbatim} |
| 78 | +from __future__ import division |
| 79 | +\end{verbatim} |
| 80 | +
|
| 81 | +the expression \code{11 / 4} would evaluate to \code{2.75}. By actually |
| 82 | +importing the __future__ module and evaluating its variables, you can see |
| 83 | +when a new feature was first added to the language and when it will becode |
| 84 | +the default: |
| 85 | +
|
| 86 | +\begin{verbatim} |
| 87 | +>>> import __future__ |
| 88 | +>>> __future__.division |
| 89 | +_Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192) |
| 90 | +\end{verbatim} |
| 91 | +
|
| 92 | +\index{generator} |
| 93 | +\item[generator]{A function that returns an iterator. It looks like a |
| 94 | +normal function except that the \keyword{yield} keyword is used instead of |
| 95 | +{}\keyword{return}. Generator functions often contain one or more |
| 96 | +{}\keyword{for} or \keyword{while} loops that \keyword{yield} elements back to |
| 97 | +the caller. The function execution is stopped at the \keyword{yield} keyword |
| 98 | +(returning the result) and is resumed there when the next element is |
| 99 | +requested by calling the \function{next()} method of the returned iterator.} |
| 100 | +
|
| 101 | +\index{GIL} |
| 102 | +\item[GIL]{See \em{global interpreter lock}.} |
| 103 | +
|
| 104 | +\index{global interpreter lock} |
| 105 | +\item[global interpreter lock]{the lock used by Python threads to assure |
| 106 | +that only one thread can be run at a time. This simplifies Python by |
| 107 | +assuring that no two processes can access the same memory at the same time. |
| 108 | +Locking the entire interpreter makes it easier for the interpreter to be |
| 109 | +multi-threaded, at the expense of some parallelism on multi-processor |
| 110 | +machines. Efforts have been made in the past to create a "free-threaded" |
| 111 | +interpreter (one which locks shared data at a much finer granularity), but |
| 112 | +performance suffered in the common single-processor case.} |
| 113 | +
|
| 114 | +\index{IDLE} |
| 115 | +\item[IDLE]{an Integrated Development Environment for Python. IDLE is a |
| 116 | +basic editor and intepreter environment that ships with the standard |
| 117 | +distribution of Python. Good for beginners and those on a budget, it also |
| 118 | +serves as clear example code for those wanting to implement a moderately |
| 119 | +sophisticated, multi-platform GUI application.} |
| 120 | +
|
| 121 | +\index{immutable} |
| 122 | +\item[immutable]{A object with fixed value. Immutable objects are numbers, |
| 123 | +strings or tuples (and more). Such an object cannot be altered. A new object |
| 124 | +has to be created if a different value has to be stored. They play an |
| 125 | +important role in places where a constant hash value is needed. For example |
| 126 | +as a key in a dictionary.} |
| 127 | +
|
| 128 | +\index{integer division} |
| 129 | +\item[integer division]{Mathematical division discarding any remainder. For |
| 130 | +example, the expression \code{11 / 4} currently evaluates to 2 in contrast |
| 131 | +to the 2.75 returned by float division. Also called "floor division". When |
| 132 | +dividing two integers the outcome will always be another integer (having the |
| 133 | +floor function applied to it). However, if one of the operands is another |
| 134 | +numeric type (such as a float), the result will be coerced (see coercion) to |
| 135 | +a common type. For example, a integer divided by a float will result in a |
| 136 | +float value, possibly with a decimal fraction. Integer division can be |
| 137 | +forced by using the \code{//} operator instead of the \code{/} operator. |
| 138 | +See also, __future__.} |
| 139 | +
|
| 140 | +\index{interactive} |
| 141 | +\item[interactive]{Python has an interactive interpreter which means that |
| 142 | +you can try out things and directly see its result. Just launch |
| 143 | +{}\code{python} with no arguments (possibly by selecting it from your |
| 144 | +computer's main menu). It is a very powerful way to test out new ideas or |
| 145 | +inspect modules and packages (remember \code{help(x)}).} |
| 146 | +
|
| 147 | +\index{interpreted} |
| 148 | +\item[interpreted]{Python is an interpreted language, opposed to a compiled |
| 149 | +one. This means that the source files can be run right away without first |
| 150 | +making an executable which is then run. Interpreted languages typicaly have |
| 151 | +a shorter development/debug cycle than compiled ones. See also |
| 152 | +{}\em{interactive}.} |
| 153 | +
|
| 154 | +\index{iterable} |
| 155 | +\item[iterable]{A container object capable of returning its members one at a |
| 156 | +time. Examples of iterables include all sequence types (\class{list}, |
| 157 | +{}\class{str}, \class{tuple}, etc.) and some non-sequence types like |
| 158 | +{}\class{dict} and \class{file} and objects of any classes you define with |
| 159 | +an \function{__iter__} or \function{__getitem__} method. Iterables can be |
| 160 | +used in a \keyword{for} loop and in many other places where a sequence is |
| 161 | +needed (\function{zip}, \function{map}, ...). When an iterable object is |
| 162 | +passed as an argument to the builtin function \function{iter()}, it returns |
| 163 | +an iterator for the object. This iterator is good for one pass over the set |
| 164 | +of values. When using iterables, it is usually not necessary to call |
| 165 | +{}\function{iter()} or deal with iterator objects yourself - the \code{for} |
| 166 | +statement does that automatically for you, creating a temporary unnamed |
| 167 | +variable to hold the iterator for the duration of the loop. See also |
| 168 | +iterator, sequence and generator.} |
| 169 | +
|
| 170 | +\index{iterator} |
| 171 | +\item[iterator]{An object representing a stream of data. Repeated calls to |
| 172 | +the iterator's \function{next()} method return successive items in the |
| 173 | +stream. When no more data is available a \exception{StopIteration} |
| 174 | +exception is raised instead. At this point the iterator object is exhausted |
| 175 | +and any further calls to its \function{next()} method just raise |
| 176 | +{}\exception{StopIteration} again. Iterators are required to have an |
| 177 | +{}\function{__iter__()} method that returns the iterator object itself so |
| 178 | +every iterator is also iterable and may be used in most places where other |
| 179 | +iterables are accepted. One notable exception is code that attempts |
| 180 | +multiple iteration passes. A container object (such as a list) produces a |
| 181 | +fresh new iterator each time you pass it to the \function{iter()} function |
| 182 | +or use it in a \function{for} loop. Attempting this with an iterator will |
| 183 | +just return the same exhausted iterator object from the second iteration |
| 184 | +pass and on, making it appear like an empty container.} |
| 185 | +
|
| 186 | +\index{list comprehension} |
| 187 | +\item[list comprehension]{A compact way to process all or a subset of elements |
| 188 | +in a sequence and return a list with the results. \code{result = ["0x\%02x" |
| 189 | +\% x for x in range(256) if x \% 2 == 0]} generates a list of strings |
| 190 | +containing hex numbers (0x..) that are even and in the range from 0 to 255. |
| 191 | +The \keyword{if} clause is optional. If omitted, all elements in |
| 192 | +{}\code{range(256)} are processed in that case.} |
| 193 | +
|
| 194 | +\index{mapping} |
| 195 | +\item[mapping]{A container object (such as \class{dict}) that supports |
| 196 | +arbitrary key lookups using the special method \function{__getitem__()}.} |
| 197 | +
|
| 198 | +\index{metaclass} |
| 199 | +\item[metaclass]{The class of a class. Class definitions create a class |
| 200 | +name, a class dictionary, and a list of base classes. The metaclass is |
| 201 | +responsible for taking those three arguments and creating the class. Most |
| 202 | +object oriented programming languages provide a default implementation. |
| 203 | +What makes Python special is that it is possible to create custom |
| 204 | +metaclasses. Most users never need this tool, but when the need arises, |
| 205 | +metaclasses can provide powerful, elegant solutions. They have been used |
| 206 | +for logging attribute access, adding thread-safety, tracking object |
| 207 | +creation, implementing singletons, and many other tasks.} |
| 208 | +
|
| 209 | +\index{LBYL} |
| 210 | +\item[LBYL]{Look before you leap. This coding style explicitly tests for |
| 211 | +pre-conditions before making calls or lookups. This style contrasts with |
| 212 | +the EAFP approach and is characterized the presence of many \keyword{if} |
| 213 | +statements.} |
| 214 | +
|
| 215 | +\index{mutable} |
| 216 | +\item[mutable]{Mutable objects can change their value but keep their |
| 217 | +\function{id()}. See also immutable.} |
| 218 | +
|
| 219 | +\index{namespace} |
| 220 | +\item[namespace]{The place where a variable is stored. Namespaces are |
| 221 | +implemented as dictionary. There is the local, global and builtins |
| 222 | +namespace and the nested namespaces in objects (in methods). Namespaces |
| 223 | +support modularity by preventing naming conflicts. For instance, the |
| 224 | +functions \function{__builtins__.open()} and \function{os.open()} are |
| 225 | +distinguished by their namespaces. Namespaces also aid readability and |
| 226 | +maintainabilty by making it clear which modules implement a function. For |
| 227 | +instance, writing \function{random.seed()} or \function{itertools.izip()} |
| 228 | +makes it clear that those functions are implemented by the \module{random} |
| 229 | +and \module{itertools} modules respectively.} |
| 230 | +
|
| 231 | +\index{nested scope} |
| 232 | +\item[nested scope]{The ability to refer to a variable in an enclosing |
| 233 | +definition. For instance, a function defined inside another function can |
| 234 | +refer to variables in the outer function. Note that nested scopes work only |
| 235 | +for reference and not for assignment which will always write to the |
| 236 | +innermost scope. In contrast, local variables both read and write in the |
| 237 | +innermost scope. Likewise, global variables read and write to the global |
| 238 | +namespace.} |
| 239 | +
|
| 240 | +\index{new-style class} |
| 241 | +\item[new-style class]{Any class that inherits from \class{object}. This |
| 242 | +includes all built-in types like \class{list} and \class{dict}. Only new |
| 243 | +style classes can use Python's newer, versatile features like |
| 244 | +{}\var{__slots__}, descriptors, properties, \var{__getattribute__}, class |
| 245 | +methods, and static methods.} |
| 246 | +
|
| 247 | +\index{Python3000} |
| 248 | +\item[Python3000]{A mythical python release, allowed not to be backward |
| 249 | +compatible, with telepathic interface.} |
| 250 | +
|
| 251 | +\index{sequence} |
| 252 | +\item[sequence]{An iterable which supports efficient element access using |
| 253 | +integer indices via the \function{__getitem__} and \function{__len()__} |
| 254 | +special methods. Some builtin sequence types are \class{list}, \class{str}, |
| 255 | +{}\class{tuple}, and \class{unicode}. Note that \class{dict} also supports |
| 256 | +{}\function{__getitem__} and \function{__len__}, but is considered a mapping |
| 257 | +rather than a sequence because the lookups use arbitrary immutable keys |
| 258 | +rather than integers.} |
| 259 | +
|
| 260 | +\index{Zen of Python} |
| 261 | +\item[Zen of Python]{listing of Python design principles and philosophies |
| 262 | +that are helpful in understanding and using the language. The listing can |
| 263 | +be found by typing "import this" at the interactive prompt.} |
| 264 | +
|
| 265 | +\end{description} |
0 commit comments