From a54754719d5f44a898b549ae8ad6940f5a04ed42 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 16 Mar 1995 14:44:07 +0000 Subject: made palatable for latex2html: removed $math$, added braces to \item[\tt...] --- Doc/ref.tex | 2 +- Doc/ref/ref.tex | 2 +- Doc/ref/ref2.tex | 11 ++++--- Doc/ref/ref3.tex | 97 ++++++++++++++++++++++++++++---------------------------- Doc/ref/ref5.tex | 69 +++++++++++++++++++++------------------- Doc/ref2.tex | 11 ++++--- Doc/ref3.tex | 97 ++++++++++++++++++++++++++++---------------------------- Doc/ref5.tex | 69 +++++++++++++++++++++------------------- 8 files changed, 186 insertions(+), 172 deletions(-) diff --git a/Doc/ref.tex b/Doc/ref.tex index a61c2de..ae1a13e 100644 --- a/Doc/ref.tex +++ b/Doc/ref.tex @@ -1,4 +1,4 @@ -\documentstyle[twoside,11pt,myformat]{report} +\documentstyle[twoside,11pt,myformat,html]{report} \title{Python Reference Manual} diff --git a/Doc/ref/ref.tex b/Doc/ref/ref.tex index a61c2de..ae1a13e 100644 --- a/Doc/ref/ref.tex +++ b/Doc/ref/ref.tex @@ -1,4 +1,4 @@ -\documentstyle[twoside,11pt,myformat]{report} +\documentstyle[twoside,11pt,myformat,html]{report} \title{Python Reference Manual} diff --git a/Doc/ref/ref2.tex b/Doc/ref/ref2.tex index b9593b8..2757ab1 100644 --- a/Doc/ref/ref2.tex +++ b/Doc/ref/ref2.tex @@ -294,11 +294,12 @@ Although both lower case `l' and upper case `L' are allowed as suffix for long integers, it is strongly recommended to always use `L', since the letter `l' looks too much like the digit `1'. -Plain integer decimal literals must be at most $2^{31} - 1$ (i.e., the -largest positive integer, assuming 32-bit arithmetic). Plain octal and -hexadecimal literals may be as large as $2^{32} - 1$, but values -larger than $2^{31} - 1$ are converted to a negative value by -subtracting $2^{32}$. There is no limit for long integer literals. +Plain integer decimal literals must be at most 2147483647 (i.e., the +largest positive integer, using 32-bit arithmetic). Plain octal and +hexadecimal literals may be as large as 4294967295, but values larger +than 2147483647 are converted to a negative value by subtracting +4294967296. There is no limit for long integer literals apart from +what can be stored in available memory. Some examples of plain and long integer literals: diff --git a/Doc/ref/ref3.tex b/Doc/ref/ref3.tex index 152b1bf..56bf8e1 100644 --- a/Doc/ref/ref3.tex +++ b/Doc/ref/ref3.tex @@ -130,14 +130,14 @@ There are two types of integers: \begin{description} \item[Plain integers] -These represent numbers in the range $-2^{31}$ through $2^{31}-1$. +These represent numbers in the range -2147483648 through 2147483647. (The range may be larger on machines with a larger natural word size, but not smaller.) When the result of an operation falls outside this range, the exception \verb@OverflowError@ is raised. For the purpose of shift and mask operations, integers are assumed to have a binary, 2's complement notation using 32 or more bits, and -hiding no bits from the user (i.e., all $2^{32}$ different bit +hiding no bits from the user (i.e., all 4294967296 different bit patterns correspond to different values). \obindex{plain integer} @@ -173,9 +173,9 @@ C implementation for the accepted range and handling of overflow. \item[Sequences] These represent finite ordered sets indexed by natural numbers. The built-in function \verb@len()@ returns the number of elements -of a sequence. When this number is $n$, the index set contains -the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence -\verb@a@ is selected by \verb@a[i]@. +of a sequence. When this number is \var{n}, the index set contains +the numbers 0, 1, \ldots, \var{n}-1. Element \var{i} of sequence +\var{a} is selected by \code{\var{a}[\var{i}]}. \obindex{seqence} \bifuncindex{len} \index{index operation} @@ -183,9 +183,10 @@ the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence \index{subscription} Sequences also support slicing: \verb@a[i:j]@ selects all elements -with index $k$ such that $i <= k < j$. When used as an expression, -a slice is a sequence of the same type --- this implies that the -index set is renumbered so that it starts at 0 again. +with index \var{k} such that \var{i} \code{<=} \var{k} \code{<} +\var{j}. When used as an expression, a slice is a sequence of the +same type --- this implies that the index set is renumbered so that it +starts at 0 again. \index{slicing} Sequences are distinguished according to their mutability: @@ -599,14 +600,14 @@ For \verb@__str__@, the default is to use \verb@__repr__@. \begin{description} -\item[\tt __init__(self, args...)] +\item[{\tt __init__(self, args...)}] Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an \code{__init__} method the derived class's \code{__init__} method must explicitly call it to ensure proper initialization of the base class part of the instance. -\item[\tt __del__(self)] +\item[{\tt __del__(self)}] Called when the instance is about to be destroyed. If a base class has an \code{__del__} method the derived class's \code{__del__} method must explicitly call it to ensure proper deletion of the base class @@ -621,7 +622,7 @@ Note that \code{del x} doesn't directly call \code{x.__del__} --- the former decrements the reference count for \code{x} by one, but \code{x,__del__} is only called when its reference count reaches zero. -\item[\tt __repr__(self)] +\item[{\tt __repr__(self)}] Called by the \verb@repr()@ built-in function and by string conversions (reverse or backward quotes) to compute the string representation of an object. \indexii{string}{conversion} @@ -629,11 +630,11 @@ Called by the \verb@repr()@ built-in function and by string conversions \indexii{backward}{quotes} \index{back-quotes} -\item[\tt __str__(self)] +\item[{\tt __str__(self)}] Called by the \verb@str()@ built-in function and by the \verb@print@ statement compute the string representation of an object. -\item[\tt __cmp__(self, other)] +\item[{\tt __cmp__(self, other)}] Called by all comparison operations. Should return -1 if \verb@self < other@, 0 if \verb@self == other@, +1 if \verb@self > other@. If no \code{__cmp__} operation is defined, class @@ -642,7 +643,7 @@ instances are compared by object identity (``address''). exceptions raised by comparisons are ignored, and the objects will be considered equal in this case.) -\item[\tt __hash__(self)] +\item[{\tt __hash__(self)}] Called for the key object for dictionary operations, and by the built-in function \code{hash()}. Should return a 32-bit integer usable as a hash value @@ -659,7 +660,7 @@ implements a \code{__cmp__} method it should not implement key's hash value is a constant. \obindex{dictionary} -\item[\tt __call__(self, *args)] +\item[{\tt __call__(self, *args)}] Called when the instance is ``called'' as a function. \end{description} @@ -672,7 +673,7 @@ access for class instances. \begin{description} -\item[\tt __getattr__(self, name)] +\item[{\tt __getattr__(self, name)}] Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for \code{self}). \code{name} is the attribute name. @@ -687,7 +688,7 @@ Note that at least for instance variables, \code{__getattr__} can fake total control by simply not inserting any values in the instance attribute dictionary. -\item[\tt __setattr__(self, name, value)] +\item[{\tt __setattr__(self, name, value)}] Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value as an instance attribute). \code{name} is the attribute name, \code{value} is the @@ -699,7 +700,7 @@ cause a recursive call. Instead, it should insert the value in the dictionary of instance attributes, e.g. \code{self.__dict__[name] = value}. -\item[\tt __delattr__(self, name)] +\item[{\tt __delattr__(self, name)}] Like \code{__setattr__} but for attribute deletion instead of assignment. @@ -710,22 +711,22 @@ assignment. \begin{description} -\item[\tt __len__(self)] +\item[{\tt __len__(self)}] Called to implement the built-in function \verb@len()@. Should return the length of the object, an integer \verb@>=@ 0. Also, an object whose \verb@__len__()@ method returns 0 is considered to be false in a Boolean context. -\item[\tt __getitem__(self, key)] +\item[{\tt __getitem__(self, key)}] Called to implement evaluation of \verb@self[key]@. Note that the special interpretation of negative keys (if the class wishes to emulate a sequence type) is up to the \verb@__getitem__@ method. -\item[\tt __setitem__(self, key, value)] +\item[{\tt __setitem__(self, key, value)}] Called to implement assignment to \verb@self[key]@. Same note as for \verb@__getitem__@. -\item[\tt __delitem__(self, key)] +\item[{\tt __delitem__(self, key)}] Called to implement deletion of \verb@self[key]@. Same note as for \verb@__getitem__@. @@ -736,18 +737,18 @@ Called to implement deletion of \verb@self[key]@. Same note as for \begin{description} -\item[\tt __getslice__(self, i, j)] +\item[{\tt __getslice__(self, i, j)}] Called to implement evaluation of \verb@self[i:j]@. Note that missing \verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@, respectively, and \verb@len(self)@ has been added (once) to originally negative \verb@i@ or \verb@j@ by the time this function is called (unlike for \verb@__getitem__@). -\item[\tt __setslice__(self, i, j, sequence)] +\item[{\tt __setslice__(self, i, j, sequence)}] Called to implement assignment to \verb@self[i:j]@. Same notes as for \verb@__getslice__@. -\item[\tt __delslice__(self, i, j)] +\item[{\tt __delslice__(self, i, j)}] Called to implement deletion of \verb@self[i:j]@. Same notes as for \verb@__getslice__@. @@ -758,34 +759,34 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for \begin{description} -\item[\tt __add__(self, other)]\itemjoin -\item[\tt __sub__(self, other)]\itemjoin -\item[\tt __mul__(self, other)]\itemjoin -\item[\tt __div__(self, other)]\itemjoin -\item[\tt __mod__(self, other)]\itemjoin -\item[\tt __divmod__(self, other)]\itemjoin -\item[\tt __pow__(self, other)]\itemjoin -\item[\tt __lshift__(self, other)]\itemjoin -\item[\tt __rshift__(self, other)]\itemjoin -\item[\tt __and__(self, other)]\itemjoin -\item[\tt __xor__(self, other)]\itemjoin -\item[\tt __or__(self, other)]\itembreak +\item[{\tt __add__(self, other)}]\itemjoin +\item[{\tt __sub__(self, other)}]\itemjoin +\item[{\tt __mul__(self, other)}]\itemjoin +\item[{\tt __div__(self, other)}]\itemjoin +\item[{\tt __mod__(self, other)}]\itemjoin +\item[{\tt __divmod__(self, other)}]\itemjoin +\item[{\tt __pow__(self, other)}]\itemjoin +\item[{\tt __lshift__(self, other)}]\itemjoin +\item[{\tt __rshift__(self, other)}]\itemjoin +\item[{\tt __and__(self, other)}]\itemjoin +\item[{\tt __xor__(self, other)}]\itemjoin +\item[{\tt __or__(self, other)}]\itembreak Called to implement the binary arithmetic operations (\verb@+@, \verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@, \verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@). -\item[\tt __neg__(self)]\itemjoin -\item[\tt __pos__(self)]\itemjoin -\item[\tt __abs__(self)]\itemjoin -\item[\tt __invert__(self)]\itembreak +\item[{\tt __neg__(self)}]\itemjoin +\item[{\tt __pos__(self)}]\itemjoin +\item[{\tt __abs__(self)}]\itemjoin +\item[{\tt __invert__(self)}]\itembreak Called to implement the unary arithmetic operations (\verb@-@, \verb@+@, \verb@abs()@ and \verb@~@). -\item[\tt __nonzero__(self)] +\item[{\tt __nonzero__(self)}] Called to implement boolean testing; should return 0 or 1. An alternative name for this method is \verb@__len__@. -\item[\tt __coerce__(self, other)] +\item[{\tt __coerce__(self, other)}] Called to implement ``mixed-mode'' numeric arithmetic. Should either return a tuple containing self and other converted to a common numeric type, or None if no way of conversion is known. When the common type @@ -803,14 +804,14 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and user-defined classes implementing sequences, mappings or numbers, but currently it doesn't --- hence this strange exception.} -\item[\tt __int__(self)]\itemjoin -\item[\tt __long__(self)]\itemjoin -\item[\tt __float__(self)]\itembreak +\item[{\tt __int__(self)}]\itemjoin +\item[{\tt __long__(self)}]\itemjoin +\item[{\tt __float__(self)}]\itembreak Called to implement the built-in functions \verb@int()@, \verb@long()@ and \verb@float()@. Should return a value of the appropriate type. -\item[\tt __oct__(self)]\itemjoin -\item[\tt __hex__(self)]\itembreak +\item[{\tt __oct__(self)}]\itemjoin +\item[{\tt __hex__(self)}]\itembreak Called to implement the built-in functions \verb@oct()@ and \verb@hex()@. Should return a string value. diff --git a/Doc/ref/ref5.tex b/Doc/ref/ref5.tex index af385aa..3db2528 100644 --- a/Doc/ref/ref5.tex +++ b/Doc/ref/ref5.tex @@ -307,9 +307,10 @@ The primary must evaluate to a sequence object. The lower and upper bound expressions, if present, must evaluate to plain integers; defaults are zero and the sequence's length, respectively. If either bound is negative, the sequence's length is added to it. The slicing -now selects all items with index $k$ such that $i <= k < j$ where $i$ -and $j$ are the specified lower and upper bounds. This may be an -empty sequence. It is not an error if $i$ or $j$ lie outside the +now selects all items with index \var{k} such that +\code{\var{i} <= \var{k} < \var{j}} where \var{i} +and \var{j} are the specified lower and upper bounds. This may be an +empty sequence. It is not an error if \var{i} or \var{j} lie outside the range of valid indexes (such items don't exist so they aren't selected). @@ -477,10 +478,11 @@ arguments are converted to a common type. They shift the first argument to the left or right by the number of bits given by the second argument. -A right shift by $n$ bits is defined as division by $2^n$. A left -shift by $n$ bits is defined as multiplication with $2^n$; for plain -integers there is no overflow check so this drops bits and flip the -sign if the result is not less than $2^{31}$ in absolute value. +A right shift by \var{n} bits is defined as division by +\code{pow(2,\var{n})}. A left shift by \var{n} bits is defined as +multiplication with \code{pow(2,\var{n})}; for plain integers there is +no overflow check so this drops bits and flips the sign if the result +is not less than \code{pow(2,31)} in absolute value. Negative shift counts raise a \verb@ValueError@ exception. \exindex{ValueError} @@ -530,20 +532,21 @@ comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in" Comparisons yield integer values: 1 for true, 0 for false. -Comparisons can be chained arbitrarily, e.g. $x < y <= z$ is -equivalent to $x < y$ \verb@and@ $y <= z$, except that $y$ is -evaluated only once (but in both cases $z$ is not evaluated at all -when $x < y$ is found to be false). +Comparisons can be chained arbitrarily, e.g. \code{x < y <= z} is +equivalent to \code{x < y and y <= z}, except that \code{y} is +evaluated only once (but in both cases \code{z} is not evaluated at all +when \code{x < y} is found to be false). \indexii{chaining}{comparisons} -\catcode`\_=8 -Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to -$e_0 op_1 e_1$ \verb@and@ $e_1 op_2 e_2$ \verb@and@ ... \verb@and@ -$e_{n-1} op_n e_n$, except that each expression is evaluated at most once. +Formally, if \var{a}, \var{b}, \var{c}, \ldots, \var{y}, \var{z} are +expressions and \var{opa}, \var{opb}, \ldots, \var{opy} are comparison +operators, then \var{a opa b opb c} \ldots \var{y opy z} is equivalent +to \var{a opa b} \code{and} \var{b opb c} \code{and} \ldots \code{and} +\var{y opy z}, except that each expression is evaluated at most once. -Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison -between $e_0$ and $e_2$, e.g. $x < y > z$ is perfectly legal. -\catcode`\_=12 +Note that \var{a opa b opb c} doesn't imply any kind of comparison +between \var{a} and \var{c}, so that e.g.\ \code{x < y > z} is +perfectly legal (though perhaps not pretty). The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below @@ -557,7 +560,7 @@ ordered consistently but arbitrarily. (This unusual definition of comparison is done to simplify the definition of operations like sorting and the \verb@in@ and -\verb@not in@ operators.) +\verb@not@ \verb@in@ operators.) Comparison of objects of the same type depends on the type: @@ -592,11 +595,12 @@ execution of a program. \end{itemize} The operators \verb@in@ and \verb@not in@ test for sequence -membership: if $y$ is a sequence, $x ~\verb@in@~ y$ is true if and -only if there exists an index $i$ such that $x = y[i]$. -$x ~\verb@not in@~ y$ yields the inverse truth value. The exception -\verb@TypeError@ is raised when $y$ is not a sequence, or when $y$ is -a string and $x$ is not a string of length one.% +membership: if \var{y} is a sequence, \code{\var{x} in \var{y}} is +true if and only if there exists an index \var{i} such that +\code{\var{x} = \var{y}[\var{i}]}. +\code{\var{x} not in \var{y}} yields the inverse truth value. The +exception \verb@TypeError@ is raised when \var{y} is not a sequence, +or when \var{y} is a string and \var{x} is not a string of length one.% \footnote{The latter restriction is sometimes a nuisance.} \opindex{in} \opindex{not in} @@ -604,8 +608,9 @@ a string and $x$ is not a string of length one.% \obindex{sequence} The operators \verb@is@ and \verb@is not@ test for object identity: -$x ~\verb@is@~ y$ is true if and only if $x$ and $y$ are the same -object. $x ~\verb@is not@~ y$ yields the inverse truth value. +\var{x} \code{is} \var{y} is true if and only if \var{x} and \var{y} +are the same object. \var{x} \code{is not} \var{y} yields the inverse +truth value. \opindex{is} \opindex{is not} \indexii{identity}{test} @@ -632,14 +637,14 @@ other values are interpreted as true. The operator \verb@not@ yields 1 if its argument is false, 0 otherwise. \opindex{not} -The condition $x ~\verb@and@~ y$ first evaluates $x$; if $x$ is false, -its value is returned; otherwise, $y$ is evaluated and the resulting -value is returned. +The condition \var{x} \verb@and@ \var{y} first evaluates \var{x}; if +\var{x} is false, its value is returned; otherwise, \var{y} is +evaluated and the resulting value is returned. \opindex{and} -The condition $x ~\verb@or@~ y$ first evaluates $x$; if $x$ is true, -its value is returned; otherwise, $y$ is evaluated and the resulting -value is returned. +The condition \var{x} \verb@or@ \var{y} first evaluates \var{x}; if +\var{x} is true, its value is returned; otherwise, \var{y} is +evaluated and the resulting value is returned. \opindex{or} (Note that \verb@and@ and \verb@or@ do not restrict the value and type diff --git a/Doc/ref2.tex b/Doc/ref2.tex index b9593b8..2757ab1 100644 --- a/Doc/ref2.tex +++ b/Doc/ref2.tex @@ -294,11 +294,12 @@ Although both lower case `l' and upper case `L' are allowed as suffix for long integers, it is strongly recommended to always use `L', since the letter `l' looks too much like the digit `1'. -Plain integer decimal literals must be at most $2^{31} - 1$ (i.e., the -largest positive integer, assuming 32-bit arithmetic). Plain octal and -hexadecimal literals may be as large as $2^{32} - 1$, but values -larger than $2^{31} - 1$ are converted to a negative value by -subtracting $2^{32}$. There is no limit for long integer literals. +Plain integer decimal literals must be at most 2147483647 (i.e., the +largest positive integer, using 32-bit arithmetic). Plain octal and +hexadecimal literals may be as large as 4294967295, but values larger +than 2147483647 are converted to a negative value by subtracting +4294967296. There is no limit for long integer literals apart from +what can be stored in available memory. Some examples of plain and long integer literals: diff --git a/Doc/ref3.tex b/Doc/ref3.tex index 152b1bf..56bf8e1 100644 --- a/Doc/ref3.tex +++ b/Doc/ref3.tex @@ -130,14 +130,14 @@ There are two types of integers: \begin{description} \item[Plain integers] -These represent numbers in the range $-2^{31}$ through $2^{31}-1$. +These represent numbers in the range -2147483648 through 2147483647. (The range may be larger on machines with a larger natural word size, but not smaller.) When the result of an operation falls outside this range, the exception \verb@OverflowError@ is raised. For the purpose of shift and mask operations, integers are assumed to have a binary, 2's complement notation using 32 or more bits, and -hiding no bits from the user (i.e., all $2^{32}$ different bit +hiding no bits from the user (i.e., all 4294967296 different bit patterns correspond to different values). \obindex{plain integer} @@ -173,9 +173,9 @@ C implementation for the accepted range and handling of overflow. \item[Sequences] These represent finite ordered sets indexed by natural numbers. The built-in function \verb@len()@ returns the number of elements -of a sequence. When this number is $n$, the index set contains -the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence -\verb@a@ is selected by \verb@a[i]@. +of a sequence. When this number is \var{n}, the index set contains +the numbers 0, 1, \ldots, \var{n}-1. Element \var{i} of sequence +\var{a} is selected by \code{\var{a}[\var{i}]}. \obindex{seqence} \bifuncindex{len} \index{index operation} @@ -183,9 +183,10 @@ the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence \index{subscription} Sequences also support slicing: \verb@a[i:j]@ selects all elements -with index $k$ such that $i <= k < j$. When used as an expression, -a slice is a sequence of the same type --- this implies that the -index set is renumbered so that it starts at 0 again. +with index \var{k} such that \var{i} \code{<=} \var{k} \code{<} +\var{j}. When used as an expression, a slice is a sequence of the +same type --- this implies that the index set is renumbered so that it +starts at 0 again. \index{slicing} Sequences are distinguished according to their mutability: @@ -599,14 +600,14 @@ For \verb@__str__@, the default is to use \verb@__repr__@. \begin{description} -\item[\tt __init__(self, args...)] +\item[{\tt __init__(self, args...)}] Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an \code{__init__} method the derived class's \code{__init__} method must explicitly call it to ensure proper initialization of the base class part of the instance. -\item[\tt __del__(self)] +\item[{\tt __del__(self)}] Called when the instance is about to be destroyed. If a base class has an \code{__del__} method the derived class's \code{__del__} method must explicitly call it to ensure proper deletion of the base class @@ -621,7 +622,7 @@ Note that \code{del x} doesn't directly call \code{x.__del__} --- the former decrements the reference count for \code{x} by one, but \code{x,__del__} is only called when its reference count reaches zero. -\item[\tt __repr__(self)] +\item[{\tt __repr__(self)}] Called by the \verb@repr()@ built-in function and by string conversions (reverse or backward quotes) to compute the string representation of an object. \indexii{string}{conversion} @@ -629,11 +630,11 @@ Called by the \verb@repr()@ built-in function and by string conversions \indexii{backward}{quotes} \index{back-quotes} -\item[\tt __str__(self)] +\item[{\tt __str__(self)}] Called by the \verb@str()@ built-in function and by the \verb@print@ statement compute the string representation of an object. -\item[\tt __cmp__(self, other)] +\item[{\tt __cmp__(self, other)}] Called by all comparison operations. Should return -1 if \verb@self < other@, 0 if \verb@self == other@, +1 if \verb@self > other@. If no \code{__cmp__} operation is defined, class @@ -642,7 +643,7 @@ instances are compared by object identity (``address''). exceptions raised by comparisons are ignored, and the objects will be considered equal in this case.) -\item[\tt __hash__(self)] +\item[{\tt __hash__(self)}] Called for the key object for dictionary operations, and by the built-in function \code{hash()}. Should return a 32-bit integer usable as a hash value @@ -659,7 +660,7 @@ implements a \code{__cmp__} method it should not implement key's hash value is a constant. \obindex{dictionary} -\item[\tt __call__(self, *args)] +\item[{\tt __call__(self, *args)}] Called when the instance is ``called'' as a function. \end{description} @@ -672,7 +673,7 @@ access for class instances. \begin{description} -\item[\tt __getattr__(self, name)] +\item[{\tt __getattr__(self, name)}] Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for \code{self}). \code{name} is the attribute name. @@ -687,7 +688,7 @@ Note that at least for instance variables, \code{__getattr__} can fake total control by simply not inserting any values in the instance attribute dictionary. -\item[\tt __setattr__(self, name, value)] +\item[{\tt __setattr__(self, name, value)}] Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value as an instance attribute). \code{name} is the attribute name, \code{value} is the @@ -699,7 +700,7 @@ cause a recursive call. Instead, it should insert the value in the dictionary of instance attributes, e.g. \code{self.__dict__[name] = value}. -\item[\tt __delattr__(self, name)] +\item[{\tt __delattr__(self, name)}] Like \code{__setattr__} but for attribute deletion instead of assignment. @@ -710,22 +711,22 @@ assignment. \begin{description} -\item[\tt __len__(self)] +\item[{\tt __len__(self)}] Called to implement the built-in function \verb@len()@. Should return the length of the object, an integer \verb@>=@ 0. Also, an object whose \verb@__len__()@ method returns 0 is considered to be false in a Boolean context. -\item[\tt __getitem__(self, key)] +\item[{\tt __getitem__(self, key)}] Called to implement evaluation of \verb@self[key]@. Note that the special interpretation of negative keys (if the class wishes to emulate a sequence type) is up to the \verb@__getitem__@ method. -\item[\tt __setitem__(self, key, value)] +\item[{\tt __setitem__(self, key, value)}] Called to implement assignment to \verb@self[key]@. Same note as for \verb@__getitem__@. -\item[\tt __delitem__(self, key)] +\item[{\tt __delitem__(self, key)}] Called to implement deletion of \verb@self[key]@. Same note as for \verb@__getitem__@. @@ -736,18 +737,18 @@ Called to implement deletion of \verb@self[key]@. Same note as for \begin{description} -\item[\tt __getslice__(self, i, j)] +\item[{\tt __getslice__(self, i, j)}] Called to implement evaluation of \verb@self[i:j]@. Note that missing \verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@, respectively, and \verb@len(self)@ has been added (once) to originally negative \verb@i@ or \verb@j@ by the time this function is called (unlike for \verb@__getitem__@). -\item[\tt __setslice__(self, i, j, sequence)] +\item[{\tt __setslice__(self, i, j, sequence)}] Called to implement assignment to \verb@self[i:j]@. Same notes as for \verb@__getslice__@. -\item[\tt __delslice__(self, i, j)] +\item[{\tt __delslice__(self, i, j)}] Called to implement deletion of \verb@self[i:j]@. Same notes as for \verb@__getslice__@. @@ -758,34 +759,34 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for \begin{description} -\item[\tt __add__(self, other)]\itemjoin -\item[\tt __sub__(self, other)]\itemjoin -\item[\tt __mul__(self, other)]\itemjoin -\item[\tt __div__(self, other)]\itemjoin -\item[\tt __mod__(self, other)]\itemjoin -\item[\tt __divmod__(self, other)]\itemjoin -\item[\tt __pow__(self, other)]\itemjoin -\item[\tt __lshift__(self, other)]\itemjoin -\item[\tt __rshift__(self, other)]\itemjoin -\item[\tt __and__(self, other)]\itemjoin -\item[\tt __xor__(self, other)]\itemjoin -\item[\tt __or__(self, other)]\itembreak +\item[{\tt __add__(self, other)}]\itemjoin +\item[{\tt __sub__(self, other)}]\itemjoin +\item[{\tt __mul__(self, other)}]\itemjoin +\item[{\tt __div__(self, other)}]\itemjoin +\item[{\tt __mod__(self, other)}]\itemjoin +\item[{\tt __divmod__(self, other)}]\itemjoin +\item[{\tt __pow__(self, other)}]\itemjoin +\item[{\tt __lshift__(self, other)}]\itemjoin +\item[{\tt __rshift__(self, other)}]\itemjoin +\item[{\tt __and__(self, other)}]\itemjoin +\item[{\tt __xor__(self, other)}]\itemjoin +\item[{\tt __or__(self, other)}]\itembreak Called to implement the binary arithmetic operations (\verb@+@, \verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@, \verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@). -\item[\tt __neg__(self)]\itemjoin -\item[\tt __pos__(self)]\itemjoin -\item[\tt __abs__(self)]\itemjoin -\item[\tt __invert__(self)]\itembreak +\item[{\tt __neg__(self)}]\itemjoin +\item[{\tt __pos__(self)}]\itemjoin +\item[{\tt __abs__(self)}]\itemjoin +\item[{\tt __invert__(self)}]\itembreak Called to implement the unary arithmetic operations (\verb@-@, \verb@+@, \verb@abs()@ and \verb@~@). -\item[\tt __nonzero__(self)] +\item[{\tt __nonzero__(self)}] Called to implement boolean testing; should return 0 or 1. An alternative name for this method is \verb@__len__@. -\item[\tt __coerce__(self, other)] +\item[{\tt __coerce__(self, other)}] Called to implement ``mixed-mode'' numeric arithmetic. Should either return a tuple containing self and other converted to a common numeric type, or None if no way of conversion is known. When the common type @@ -803,14 +804,14 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and user-defined classes implementing sequences, mappings or numbers, but currently it doesn't --- hence this strange exception.} -\item[\tt __int__(self)]\itemjoin -\item[\tt __long__(self)]\itemjoin -\item[\tt __float__(self)]\itembreak +\item[{\tt __int__(self)}]\itemjoin +\item[{\tt __long__(self)}]\itemjoin +\item[{\tt __float__(self)}]\itembreak Called to implement the built-in functions \verb@int()@, \verb@long()@ and \verb@float()@. Should return a value of the appropriate type. -\item[\tt __oct__(self)]\itemjoin -\item[\tt __hex__(self)]\itembreak +\item[{\tt __oct__(self)}]\itemjoin +\item[{\tt __hex__(self)}]\itembreak Called to implement the built-in functions \verb@oct()@ and \verb@hex()@. Should return a string value. diff --git a/Doc/ref5.tex b/Doc/ref5.tex index af385aa..3db2528 100644 --- a/Doc/ref5.tex +++ b/Doc/ref5.tex @@ -307,9 +307,10 @@ The primary must evaluate to a sequence object. The lower and upper bound expressions, if present, must evaluate to plain integers; defaults are zero and the sequence's length, respectively. If either bound is negative, the sequence's length is added to it. The slicing -now selects all items with index $k$ such that $i <= k < j$ where $i$ -and $j$ are the specified lower and upper bounds. This may be an -empty sequence. It is not an error if $i$ or $j$ lie outside the +now selects all items with index \var{k} such that +\code{\var{i} <= \var{k} < \var{j}} where \var{i} +and \var{j} are the specified lower and upper bounds. This may be an +empty sequence. It is not an error if \var{i} or \var{j} lie outside the range of valid indexes (such items don't exist so they aren't selected). @@ -477,10 +478,11 @@ arguments are converted to a common type. They shift the first argument to the left or right by the number of bits given by the second argument. -A right shift by $n$ bits is defined as division by $2^n$. A left -shift by $n$ bits is defined as multiplication with $2^n$; for plain -integers there is no overflow check so this drops bits and flip the -sign if the result is not less than $2^{31}$ in absolute value. +A right shift by \var{n} bits is defined as division by +\code{pow(2,\var{n})}. A left shift by \var{n} bits is defined as +multiplication with \code{pow(2,\var{n})}; for plain integers there is +no overflow check so this drops bits and flips the sign if the result +is not less than \code{pow(2,31)} in absolute value. Negative shift counts raise a \verb@ValueError@ exception. \exindex{ValueError} @@ -530,20 +532,21 @@ comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in" Comparisons yield integer values: 1 for true, 0 for false. -Comparisons can be chained arbitrarily, e.g. $x < y <= z$ is -equivalent to $x < y$ \verb@and@ $y <= z$, except that $y$ is -evaluated only once (but in both cases $z$ is not evaluated at all -when $x < y$ is found to be false). +Comparisons can be chained arbitrarily, e.g. \code{x < y <= z} is +equivalent to \code{x < y and y <= z}, except that \code{y} is +evaluated only once (but in both cases \code{z} is not evaluated at all +when \code{x < y} is found to be false). \indexii{chaining}{comparisons} -\catcode`\_=8 -Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to -$e_0 op_1 e_1$ \verb@and@ $e_1 op_2 e_2$ \verb@and@ ... \verb@and@ -$e_{n-1} op_n e_n$, except that each expression is evaluated at most once. +Formally, if \var{a}, \var{b}, \var{c}, \ldots, \var{y}, \var{z} are +expressions and \var{opa}, \var{opb}, \ldots, \var{opy} are comparison +operators, then \var{a opa b opb c} \ldots \var{y opy z} is equivalent +to \var{a opa b} \code{and} \var{b opb c} \code{and} \ldots \code{and} +\var{y opy z}, except that each expression is evaluated at most once. -Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison -between $e_0$ and $e_2$, e.g. $x < y > z$ is perfectly legal. -\catcode`\_=12 +Note that \var{a opa b opb c} doesn't imply any kind of comparison +between \var{a} and \var{c}, so that e.g.\ \code{x < y > z} is +perfectly legal (though perhaps not pretty). The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below @@ -557,7 +560,7 @@ ordered consistently but arbitrarily. (This unusual definition of comparison is done to simplify the definition of operations like sorting and the \verb@in@ and -\verb@not in@ operators.) +\verb@not@ \verb@in@ operators.) Comparison of objects of the same type depends on the type: @@ -592,11 +595,12 @@ execution of a program. \end{itemize} The operators \verb@in@ and \verb@not in@ test for sequence -membership: if $y$ is a sequence, $x ~\verb@in@~ y$ is true if and -only if there exists an index $i$ such that $x = y[i]$. -$x ~\verb@not in@~ y$ yields the inverse truth value. The exception -\verb@TypeError@ is raised when $y$ is not a sequence, or when $y$ is -a string and $x$ is not a string of length one.% +membership: if \var{y} is a sequence, \code{\var{x} in \var{y}} is +true if and only if there exists an index \var{i} such that +\code{\var{x} = \var{y}[\var{i}]}. +\code{\var{x} not in \var{y}} yields the inverse truth value. The +exception \verb@TypeError@ is raised when \var{y} is not a sequence, +or when \var{y} is a string and \var{x} is not a string of length one.% \footnote{The latter restriction is sometimes a nuisance.} \opindex{in} \opindex{not in} @@ -604,8 +608,9 @@ a string and $x$ is not a string of length one.% \obindex{sequence} The operators \verb@is@ and \verb@is not@ test for object identity: -$x ~\verb@is@~ y$ is true if and only if $x$ and $y$ are the same -object. $x ~\verb@is not@~ y$ yields the inverse truth value. +\var{x} \code{is} \var{y} is true if and only if \var{x} and \var{y} +are the same object. \var{x} \code{is not} \var{y} yields the inverse +truth value. \opindex{is} \opindex{is not} \indexii{identity}{test} @@ -632,14 +637,14 @@ other values are interpreted as true. The operator \verb@not@ yields 1 if its argument is false, 0 otherwise. \opindex{not} -The condition $x ~\verb@and@~ y$ first evaluates $x$; if $x$ is false, -its value is returned; otherwise, $y$ is evaluated and the resulting -value is returned. +The condition \var{x} \verb@and@ \var{y} first evaluates \var{x}; if +\var{x} is false, its value is returned; otherwise, \var{y} is +evaluated and the resulting value is returned. \opindex{and} -The condition $x ~\verb@or@~ y$ first evaluates $x$; if $x$ is true, -its value is returned; otherwise, $y$ is evaluated and the resulting -value is returned. +The condition \var{x} \verb@or@ \var{y} first evaluates \var{x}; if +\var{x} is true, its value is returned; otherwise, \var{y} is +evaluated and the resulting value is returned. \opindex{or} (Note that \verb@and@ and \verb@or@ do not restrict the value and type -- cgit v0.12