Commit d4a1419f authored by Fred Drake's avatar Fred Drake

Lots of markup corrections. Some are minor, but others are not: the

contents of an \item should not be enclosed in a group!
parent cc2e48dd
...@@ -6,84 +6,97 @@ ...@@ -6,84 +6,97 @@
\begin{description} \begin{description}
\index{...} \index{...}
\item[...]{The typical Python prompt of the interactive shell when entering \item[\code{.\code{.}.}]
code for an indented code block.} The typical Python prompt of the interactive shell when entering code
for an indented code block.
\index{>>>} \index{>>>}
\item[>>>]{The typical Python prompt of the interactive shell. Often seen \item[\code{>\code{>}>}]
for code examples that can be tried right away in the interpreter.} The typical Python prompt of the interactive shell. Often seen for
code examples that can be tried right away in the interpreter.
\index{__slots__} \index{__slots__}
\item[__slots__]{A declaration inside a \emph{new-style class} that saves \item[__slots__]
memory by pre-declaring space for instance attributes and eliminating A declaration inside a \emph{new-style class} that saves memory by
instance dictionaries. Though popular, the technique is somewhat tricky to pre-declaring space for instance attributes and eliminating instance
get right and is best reserved for rare cases where there are large numbers dictionaries. Though popular, the technique is somewhat tricky to get
of instances in a memory critical application.} right and is best reserved for rare cases where there are large
numbers of instances in a memory critical application.
\index{BDFL} \index{BDFL}
\item[BDFL]{Benevolent Dictator For Life, a.k.a. \ulink{Guido van \item[BDFL]
Rossum}{http://www.python.org/~guido/}, Python's creator.} Benevolent Dictator For Life, a.k.a. \ulink{Guido van
Rossum}{http://www.python.org/~guido/}, Python's creator.
\index{byte code} \index{byte code}
\item[byte code]{The internal representation of a Python program in the \item[byte code]
interpreter. The byte code is also cached in the \code{.pyc} and The internal representation of a Python program in the interpreter.
{}\code{.pyo} files so that executing the same file is faster the second The byte code is also cached in the \code{.pyc} and \code{.pyo}
time (compilation from source to byte code can be saved). This files so that executing the same file is faster the second time
"intermediate language" is said to run on a "virtual machine" that calls the (compilation from source to byte code can be saved). This
subroutines corresponding to each bytecode.} \emph{intermediate language} is said to run on a \emph{virtual
machine} that calls the subroutines corresponding to each bytecode.
\index{classic class} \index{classic class}
\item[classic class]{Any class which does not inherit from \class{object}. \item[classic class]
See new-style class.} Any class which does not inherit from \class{object}. See
\emph{new-style class}.
\index{coercion} \index{coercion}
\item[coercion]{Converting data from one type to another. For example, \item[coercion]
{}\code{int(3.15)} coerces the floating point number to the integer, \code{3}. Converting data from one type to another. For example,
Most mathematical operations have rules for coercing their arguments to a common {}\code{int(3.15)} coerces the floating point number to the integer,
type. For instance, adding \code{3 + 4.5}, causes the integer \code{3} to be {}\code{3}. Most mathematical operations have rules for coercing
coerced to be a float \code{3.0} before adding to \code{4.5} resulting in the their arguments to a common type. For instance, adding \code{3 +
float \code{7.5}.} 4.5}, causes the integer \code{3} to be coerced to be a float
{}\code{3.0} before adding to \code{4.5} resulting in the float
{}\code{7.5}.
\index{descriptor} \index{descriptor}
\item[descriptor]{Any object that defines the methods \method{__get__()}, \item[descriptor]
\method{__set__()}, or \method{__delete__()}. When a class attribute is a Any \emph{new-style} object that defines the methods
descriptor, its special binding behavior is triggered upon attribute lookup. {}\method{__get__()}, \method{__set__()}, or \method{__delete__()}.
Normally, writing {}\var{a.b} looks up the object \var{b} in the class When a class attribute is a descriptor, its special binding behavior
dictionary for \var{a}, but if \var{b} is a descriptor, the defined method is triggered upon attribute lookup. Normally, writing \var{a.b} looks
gets called. Understanding descriptors is a key to a deep understanding of up the object \var{b} in the class dictionary for \var{a}, but if
Python because they are the basis for many features including functions, {}\var{b} is a descriptor, the defined method gets called.
methods, properties, class methods, static methods, and reference to super Understanding descriptors is a key to a deep understanding of Python
classes.} because they are the basis for many features including functions,
methods, properties, class methods, static methods, and reference to
super classes.
\index{dictionary} \index{dictionary}
\item[dictionary]{An associative array, where arbitrary keys are mapped to \item[dictionary]
values. The use of \class{dict} much resembles that for \class{list}, but An associative array, where arbitrary keys are mapped to values. The
the keys can be any object with a \function{__hash__} function, not just use of \class{dict} much resembles that for \class{list}, but the keys
integers starting from zero. Called a hash in Perl.} can be any object with a \method{__hash__()} function, not just
integers starting from zero. Called a hash in Perl.
\index{EAFP} \index{EAFP}
\item[EAFP]{Easier to ask for forgiveness than permission. This common \item[EAFP]
Python coding style assumes the existence of valid keys or attributes and Easier to ask for forgiveness than permission. This common Python
catches exceptions if the assumption proves false. This clean and fast coding style assumes the existence of valid keys or attributes and
style is characterized by the presence of many \keyword{try} and catches exceptions if the assumption proves false. This clean and
{}\keyword{except} statements. The technique contrasts with the \emph{LBYL} fast style is characterized by the presence of many \keyword{try} and
style that is common in many other languages such as C.} {}\keyword{except} statements. The technique contrasts with the
{}\emph{LBYL} style that is common in many other languages such as C.
\index{__future__} \index{__future__}
\item[__future__]{A pseudo module which programmers can use to enable \item[__future__]
new language features which are not compatible with the current interpreter. A pseudo module which programmers can use to enable new language
For example, the expression \code{11 / 4} currently evaluates to \code{2}. features which are not compatible with the current interpreter. For
If the module in which it is executed had enabled emph{true division} by example, the expression \code{11 / 4} currently evaluates to \code{2}.
executing:} If the module in which it is executed had enabled emph{true division}
by executing:
\begin{verbatim} \begin{verbatim}
from __future__ import division from __future__ import division
\end{verbatim} \end{verbatim}
the expression \code{11 / 4} would evaluate to \code{2.75}. By actually the expression \code{11 / 4} would evaluate to \code{2.75}. By
importing the \module{__future__} module and evaluating its variables, you actually importing the \refmodule[future]{__future__} module and
can see when a new feature was first added to the language and when it will evaluating its variables, you can see when a new feature was first
become the default: added to the language and when it will become the default:
\begin{verbatim} \begin{verbatim}
>>> import __future__ >>> import __future__
...@@ -92,177 +105,205 @@ _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192) ...@@ -92,177 +105,205 @@ _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
\end{verbatim} \end{verbatim}
\index{generator} \index{generator}
\item[generator]{A function that returns an iterator. It looks like a \item[generator]
normal function except that the \keyword{yield} keyword is used instead of A function that returns an iterator. It looks like a normal function
except that the \keyword{yield} keyword is used instead of
{}\keyword{return}. Generator functions often contain one or more {}\keyword{return}. Generator functions often contain one or more
{}\keyword{for} or \keyword{while} loops that \keyword{yield} elements back to {}\keyword{for} or \keyword{while} loops that \keyword{yield} elements
the caller. The function execution is stopped at the \keyword{yield} keyword back to the caller. The function execution is stopped at the
(returning the result) and is resumed there when the next element is {}\keyword{yield} keyword (returning the result) and is resumed there
requested by calling the \function{next()} method of the returned iterator.} when the next element is requested by calling the \method{next()}
method of the returned iterator.
\index{GIL} \index{GIL}
\item[GIL]{See \emph{global interpreter lock}.} \item[GIL]
See \emph{global interpreter lock}.
\index{global interpreter lock} \index{global interpreter lock}
\item[global interpreter lock]{the lock used by Python threads to assure \item[global interpreter lock]
that only one thread can be run at a time. This simplifies Python by The lock used by Python threads to assure that only one thread can be
assuring that no two processes can access the same memory at the same time. run at a time. This simplifies Python by assuring that no two
Locking the entire interpreter makes it easier for the interpreter to be processes can access the same memory at the same time. Locking the
entire interpreter makes it easier for the interpreter to be
multi-threaded, at the expense of some parallelism on multi-processor multi-threaded, at the expense of some parallelism on multi-processor
machines. Efforts have been made in the past to create a "free-threaded" machines. Efforts have been made in the past to create a
interpreter (one which locks shared data at a much finer granularity), but "free-threaded" interpreter (one which locks shared data at a much
performance suffered in the common single-processor case.} finer granularity), but performance suffered in the common
single-processor case.
\index{IDLE} \index{IDLE}
\item[IDLE]{an Integrated Development Environment for Python. IDLE is a \item[IDLE]
An Integrated Development Environment for Python. IDLE is a
basic editor and interpreter environment that ships with the standard basic editor and interpreter environment that ships with the standard
distribution of Python. Good for beginners, it also serves as clear distribution of Python. Good for beginners, it also serves as clear
example code for those wanting to implement a moderately example code for those wanting to implement a moderately
sophisticated, multi-platform GUI application.} sophisticated, multi-platform GUI application.
\index{immutable} \index{immutable}
\item[immutable]{A object with fixed value. Immutable objects are numbers, \item[immutable]
strings or tuples (and more). Such an object cannot be altered. A new object A object with fixed value. Immutable objects are numbers, strings or
tuples (and more). Such an object cannot be altered. A new object
has to be created if a different value has to be stored. They play an has to be created if a different value has to be stored. They play an
important role in places where a constant hash value is needed. For example important role in places where a constant hash value is needed. For
as a key in a dictionary.} example as a key in a dictionary.
\index{integer division} \index{integer division}
\item[integer division]{Mathematical division discarding any remainder. For \item[integer division]
example, the expression \code{11 / 4} currently evaluates to \code{2} in Mathematical division discarding any remainder. For example, the
contrast to the \code{2.75} returned by float division. Also called expression \code{11 / 4} currently evaluates to \code{2} in contrast
\emph{floor division}. When dividing two integers the outcome will always be to the \code{2.75} returned by float division. Also called
another integer (having the floor function applied to it). However, if one {}\emph{floor division}. When dividing two integers the outcome will
of the operands is another numeric type (such as a \class{float}), the result always be another integer (having the floor function applied to it).
will be coerced (see \emph{coercion}) to a common type. For example, a integer However, if one of the operands is another numeric type (such as a
divided by a float will result in a float value, possibly with a decimal {}\class{float}), the result will be coerced (see \emph{coercion}) to
fraction. Integer division can be forced by using the \code{//} operator a common type. For example, a integer divided by a float will result
instead of the \code{/} operator. in a float value, possibly with a decimal fraction. Integer division
See also, \emph{__future__}.} can be forced by using the \code{//} operator instead of the \code{/}
operator. See also \emph{__future__}.
\index{interactive} \index{interactive}
\item[interactive]{Python has an interactive interpreter which means that \item[interactive]
you can try out things and directly see its result. Just launch Python has an interactive interpreter which means that you can try out
{}\code{python} with no arguments (possibly by selecting it from your things and directly see its result. Just launch \code{python} with no
computer's main menu). It is a very powerful way to test out new ideas or arguments (possibly by selecting it from your computer's main menu).
inspect modules and packages (remember \code{help(x)}).} It is a very powerful way to test out new ideas or inspect modules and
packages (remember \code{help(x)}).
\index{interpreted} \index{interpreted}
\item[interpreted]{Python is an interpreted language, opposed to a compiled \item[interpreted]
one. This means that the source files can be run right away without first Python is an interpreted language, opposed to a compiled one. This
making an executable which is then run. Interpreted languages typically have means that the source files can be run right away without first making
an executable which is then run. Interpreted languages typically have
a shorter development/debug cycle than compiled ones. See also a shorter development/debug cycle than compiled ones. See also
{}\emph{interactive}.} {}\emph{interactive}.
\index{iterable} \index{iterable}
\item[iterable]{A container object capable of returning its members one at a \item[iterable]
time. Examples of iterables include all sequence types (such as\class{list}, A container object capable of returning its members one at a time.
Examples of iterables include all sequence types (such as\class{list},
{}\class{str}, and \class{tuple}) and some non-sequence types like {}\class{str}, and \class{tuple}) and some non-sequence types like
{}\class{dict} and \class{file} and objects of any classes you define with {}\class{dict} and \class{file} and objects of any classes you define
an \method{__iter__} or \function{__getitem__} method. Iterables can be with an \method{__iter__()} or \method{__getitem__()} method. Iterables
used in a \keyword{for} loop and in many other places where a sequence is can be used in a \keyword{for} loop and in many other places where a
needed (\function{zip}, \function{map}, ...). When an iterable object is sequence is needed (\function{zip()}, \function{map()}, ...). When an
passed as an argument to the builtin function \function{iter()}, it returns iterable object is passed as an argument to the builtin function
an iterator for the object. This iterator is good for one pass over the set {}\function{iter()}, it returns an iterator for the object. This
of values. When using iterables, it is usually not necessary to call iterator is good for one pass over the set of values. When using
{}\function{iter()} or deal with iterator objects yourself - the \code{for} iterables, it is usually not necessary to call \function{iter()} or
statement does that automatically for you, creating a temporary unnamed deal with iterator objects yourself---the \code{for} statement does
variable to hold the iterator for the duration of the loop. See also that automatically for you, creating a temporary unnamed variable to
\emph{iterator}, \emph{sequence} and \emph{generator}.} hold the iterator for the duration of the loop. See also
{}\emph{iterator}, \emph{sequence}, and \emph{generator}.
\index{iterator} \index{iterator}
\item[iterator]{An object representing a stream of data. Repeated calls to \item[iterator]
the iterator's \function{next()} method return successive items in the An object representing a stream of data. Repeated calls to the
iterator's \method{next()} method return successive items in the
stream. When no more data is available a \exception{StopIteration} stream. When no more data is available a \exception{StopIteration}
exception is raised instead. At this point, the iterator object is exhausted exception is raised instead. At this point, the iterator object is
and any further calls to its \function{next()} method just raise exhausted and any further calls to its \method{next()} method just
{}\exception{StopIteration} again. Iterators are required to have an raise \exception{StopIteration} again. Iterators are required to have
{}\function{__iter__()} method that returns the iterator object itself so an \method{__iter__()} method that returns the iterator object
every iterator is also iterable and may be used in most places where other itself so every iterator is also iterable and may be used in most
iterables are accepted. One notable exception is code that attempts places where other iterables are accepted. One notable exception is
multiple iteration passes. A container object (such as a \class{list}) code that attempts multiple iteration passes. A container object
produces a fresh new iterator each time you pass it to the \function{iter()} (such as a \class{list}) produces a fresh new iterator each time you
function or use it in a \function{for} loop. Attempting this with an iterator pass it to the \function{iter()} function or use it in a
will just return the same exhausted iterator object from the second iteration {}\keyword{for} loop. Attempting this with an iterator will just
pass, making it appear like an empty container.} return the same exhausted iterator object from the second iteration
pass, making it appear like an empty container.
\index{list comprehension} \index{list comprehension}
\item[list comprehension]{A compact way to process all or a subset of elements \item[list comprehension]
in a sequence and return a list with the results. \code{result = ["0x\%02x" A compact way to process all or a subset of elements in a sequence and
return a list with the results. \code{result = ["0x\%02x"
\% x for x in range(256) if x \% 2 == 0]} generates a list of strings \% x for x in range(256) if x \% 2 == 0]} generates a list of strings
containing hex numbers (0x..) that are even and in the range from 0 to 255. containing hex numbers (0x..) that are even and in the range from 0 to 255.
The \keyword{if} clause is optional. If omitted, all elements in The \keyword{if} clause is optional. If omitted, all elements in
{}\code{range(256)} are processed in that case.} {}\code{range(256)} are processed in that case.
\index{mapping} \index{mapping}
\item[mapping]{A container object (such as \class{dict}) that supports \item[mapping]
arbitrary key lookups using the special method \function{__getitem__()}.} A container object (such as \class{dict}) that supports arbitrary key
lookups using the special method \method{__getitem__()}.
\index{metaclass} \index{metaclass}
\item[metaclass]{The class of a class. Class definitions create a class \item[metaclass]
name, a class dictionary, and a list of base classes. The metaclass is The class of a class. Class definitions create a class name, a class
responsible for taking those three arguments and creating the class. Most dictionary, and a list of base classes. The metaclass is responsible
object oriented programming languages provide a default implementation. for taking those three arguments and creating the class. Most object
What makes Python special is that it is possible to create custom oriented programming languages provide a default implementation. What
metaclasses. Most users never need this tool, but when the need arises, makes Python special is that it is possible to create custom
metaclasses can provide powerful, elegant solutions. They have been used metaclasses. Most users never need this tool, but when the need
for logging attribute access, adding thread-safety, tracking object arises, metaclasses can provide powerful, elegant solutions. They
creation, implementing singletons, and many other tasks.} have been used for logging attribute access, adding thread-safety,
tracking object creation, implementing singletons, and many other
tasks.
\index{LBYL} \index{LBYL}
\item[LBYL]{Look before you leap. This coding style explicitly tests for \item[LBYL]
pre-conditions before making calls or lookups. This style contrasts with Look before you leap. This coding style explicitly tests for
the \emph{EAFP} approach and is characterized the presence of many pre-conditions before making calls or lookups. This style contrasts
{}\keyword{if} statements.} with the \emph{EAFP} approach and is characterized the presence of
many \keyword{if} statements.
\index{mutable} \index{mutable}
\item[mutable]{Mutable objects can change their value but keep their \item[mutable]
\function{id()}. See also immutable.} Mutable objects can change their value but keep their \function{id()}.
See also \emph{immutable}.
\index{namespace} \index{namespace}
\item[namespace]{The place where a variable is stored. Namespaces are \item[namespace]
implemented as dictionary. There is the local, global and builtins The place where a variable is stored. Namespaces are implemented as
namespace and the nested namespaces in objects (in methods). Namespaces dictionary. There is the local, global and builtins namespace and the
support modularity by preventing naming conflicts. For instance, the nested namespaces in objects (in methods). Namespaces support
functions \function{__builtins__.open()} and \function{os.open()} are modularity by preventing naming conflicts. For instance, the
distinguished by their namespaces. Namespaces also aid readability and functions \function{__builtin__.open()} and \function{os.open()} are
maintainability by making it clear which modules implement a function. For distinguished by their namespaces. Namespaces also aid readability
instance, writing \function{random.seed()} or \function{itertools.izip()} and maintainability by making it clear which modules implement a
makes it clear that those functions are implemented by the \module{random} function. For instance, writing \function{random.seed()} or
and \module{itertools} modules respectively.} {}\function{itertools.izip()} makes it clear that those functions are
implemented by the \refmodule{random} and \refmodule{itertools}
modules respectively.
\index{nested scope} \index{nested scope}
\item[nested scope]{The ability to refer to a variable in an enclosing \item[nested scope]
definition. For instance, a function defined inside another function can The ability to refer to a variable in an enclosing definition. For
refer to variables in the outer function. Note that nested scopes work only instance, a function defined inside another function can refer to
variables in the outer function. Note that nested scopes work only
for reference and not for assignment which will always write to the for reference and not for assignment which will always write to the
innermost scope. In contrast, local variables both read and write in the innermost scope. In contrast, local variables both read and write in
innermost scope. Likewise, global variables read and write to the global the innermost scope. Likewise, global variables read and write to the
namespace.} global namespace.
\index{new-style class} \index{new-style class}
\item[new-style class]{Any class that inherits from \class{object}. This \item[new-style class]
includes all built-in types like \class{list} and \class{dict}. Only Any class that inherits from \class{object}. This includes all
new-style classes can use Python's newer, versatile features like built-in types like \class{list} and \class{dict}. Only new-style
{}\var{__slots__}, descriptors, properties, \var{__getattribute__}, class classes can use Python's newer, versatile features like
methods, and static methods.} {}\var{__slots__}, descriptors, properties,
\method{__getattribute__()}, class methods, and static methods.
\index{Python3000} \index{Python3000}
\item[Python3000]{A mythical python release, allowed not to be backward \item[Python3000]
compatible, with telepathic interface.} A mythical python release, allowed not to be backward compatible, with
telepathic interface.
\index{sequence} \index{sequence}
\item[sequence]{An \emph{iterable} which supports efficient element access using \item[sequence]
integer indices via the \function{__getitem__} and \function{__len()__} An \emph{iterable} which supports efficient element access using
special methods. Some builtin sequence types are \class{list}, \class{str}, integer indices via the \method{__getitem__()} and
{}\class{tuple}, and \class{unicode}. Note that \class{dict} also supports {}\method{__len__()} special methods. Some built-in sequence types
{}\function{__getitem__} and \function{__len__}, but is considered a mapping are \class{list}, \class{str}, \class{tuple}, and \class{unicode}.
rather than a sequence because the lookups use arbitrary \emph{immutable} keys Note that \class{dict} also supports \method{__getitem__()} and
rather than integers.} {}\method{__len__()}, but is considered a mapping rather than a
sequence because the lookups use arbitrary \emph{immutable} keys
rather than integers.
\index{Zen of Python} \index{Zen of Python}
\item[Zen of Python]{listing of Python design principles and philosophies \item[Zen of Python]
that are helpful in understanding and using the language. The listing can Listing of Python design principles and philosophies that are helpful
be found by typing \code{import this} at the interactive prompt.} in understanding and using the language. The listing can be found by
typing \code{import this} at the interactive prompt.
\end{description} \end{description}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment