Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libstdtypes.tex @ 13163:a09e8635534d legacy-trunk
Don't try to guess the name of a .def file -- if one is supplied, use it,
otherwise just generate an '/export:' option.
| author | Greg Ward <gward@python.net> |
|---|---|
| date | Thu, 29 Jun 2000 23:09:20 +0000 |
| parents | e82e82b3b9ad |
| children | 5dd381aeb23b |
| rev | line source |
|---|---|
| 9083 | 1 \section{Built-in Types \label{types}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 The following sections describe the standard types that are built into |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 the interpreter. These are the numeric types, sequence types, and |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 several others, including types themselves. There is no explicit |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 Boolean type; use integers instead. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
7 \indexii{built-in}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 \indexii{Boolean}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 Some operations are supported by several object types; in particular, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 all objects can be compared, tested for truth value, and converted to |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
12 a string (with the \code{`\textrm{\ldots}`} notation). The latter |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
13 conversion is implicitly used when an object is written by the |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
14 \keyword{print}\stindex{print} statement. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 |
| 9083 | 17 \subsection{Truth Value Testing \label{truth}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
19 Any object can be tested for truth value, for use in an \keyword{if} or |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
20 \keyword{while} condition or as operand of the Boolean operations below. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 The following values are considered false: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 \stindex{if} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 \stindex{while} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 \indexii{truth}{value} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 \indexii{Boolean}{operations} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 \index{false} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 \begin{itemize} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 \item \code{None} |
| 9083 | 31 \withsubitem{(Built-in object)}{\ttindex{None}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
33 \item zero of any numeric type, for example, \code{0}, \code{0L}, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
34 \code{0.0}, \code{0j}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
36 \item any empty sequence, for example, \code{''}, \code{()}, \code{[]}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
38 \item any empty mapping, for example, \code{\{\}}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 \item instances of user-defined classes, if the class defines a |
| 9083 | 41 \method{__nonzero__()} or \method{__len__()} method, when that |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
42 method returns zero.\footnote{Additional information on these |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
43 special methods may be found in the \emph{Python Reference Manual}.} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 \end{itemize} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 All other values are considered true --- so objects of many types are |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 always true. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
49 \index{true} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
50 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
51 Operations and built-in functions that have a Boolean result always |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
52 return \code{0} for false and \code{1} for true, unless otherwise |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
53 stated. (Important exception: the Boolean operations |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 \samp{or}\opindex{or} and \samp{and}\opindex{and} always return one of |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
55 their operands.) |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
56 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
57 |
| 9083 | 58 \subsection{Boolean Operations \label{boolean}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
59 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
60 These are the Boolean operations, ordered by ascending priority: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
61 \indexii{Boolean}{operations} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
62 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
63 \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 \lineiii{\var{x} or \var{y}}{if \var{x} is false, then \var{y}, else \var{x}}{(1)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 \lineiii{\var{x} and \var{y}}{if \var{x} is false, then \var{x}, else \var{y}}{(1)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
67 \lineiii{not \var{x}}{if \var{x} is false, then \code{1}, else \code{0}}{(2)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
68 \end{tableiii} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
69 \opindex{and} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
70 \opindex{or} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
71 \opindex{not} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
72 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
73 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
74 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
75 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
76 \begin{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
77 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
78 \item[(1)] |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 These only evaluate their second argument if needed for their outcome. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
80 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
81 \item[(2)] |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
82 \samp{not} has a lower priority than non-Boolean operators, so |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
83 \code{not \var{a} == \var{b}} is interpreted as \code{not (\var{a} == |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
84 \var{b})}, and \code{\var{a} == not \var{b}} is a syntax error. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
85 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
86 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
87 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 |
| 9083 | 89 \subsection{Comparisons \label{comparisons}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
90 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
91 Comparison operations are supported by all objects. They all have the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
92 same priority (which is higher than that of the Boolean operations). |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
93 Comparisons can be chained arbitrarily; for example, \code{\var{x} < |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
94 \var{y} <= \var{z}} is equivalent to \code{\var{x} < \var{y} and |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
95 \var{y} <= \var{z}}, except that \var{y} is evaluated only once (but |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
96 in both cases \var{z} is not evaluated at all when \code{\var{x} < |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
97 \var{y}} is found to be false). |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
98 \indexii{chaining}{comparisons} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
99 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
100 This table summarizes the comparison operations: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
101 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
102 \begin{tableiii}{c|l|c}{code}{Operation}{Meaning}{Notes} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
103 \lineiii{<}{strictly less than}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
104 \lineiii{<=}{less than or equal}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
105 \lineiii{>}{strictly greater than}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
106 \lineiii{>=}{greater than or equal}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
107 \lineiii{==}{equal}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
108 \lineiii{<>}{not equal}{(1)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
109 \lineiii{!=}{not equal}{(1)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
110 \lineiii{is}{object identity}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
111 \lineiii{is not}{negated object identity}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
112 \end{tableiii} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
113 \indexii{operator}{comparison} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
114 \opindex{==} % XXX *All* others have funny characters < ! > |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
115 \opindex{is} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
116 \opindex{is not} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
117 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 \begin{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 \item[(1)] |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
124 \code{<>} and \code{!=} are alternate spellings for the same operator. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
125 (I couldn't choose between \ABC{} and \C{}! :-) |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
126 \index{ABC language@\ABC{} language} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
127 \index{language!ABC@\ABC{}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
128 \indexii{C@\C{}}{language} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
129 \code{!=} is the preferred spelling; \code{<>} is obsolescent. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
130 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
131 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
132 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
133 Objects of different types, except different numeric types, never |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
134 compare equal; such objects are ordered consistently but arbitrarily |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
135 (so that sorting a heterogeneous array yields a consistent result). |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
136 Furthermore, some types (for example, file objects) support only a |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
137 degenerate notion of comparison where any two objects of that type are |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
138 unequal. Again, such objects are ordered arbitrarily but |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
139 consistently. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
140 \indexii{object}{numeric} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
141 \indexii{objects}{comparing} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
142 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
143 Instances of a class normally compare as non-equal unless the class |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
144 \withsubitem{(instance method)}{\ttindex{__cmp__()}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
145 defines the \method{__cmp__()} method. Refer to the \emph{Python |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
146 Reference Manual} for information on the use of this method to effect |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
147 object comparisons. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
148 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
149 \strong{Implementation note:} Objects of different types except |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
150 numbers are ordered by their type names; objects of the same types |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
151 that don't support proper comparison are ordered by their address. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
152 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
153 Two more operations with the same syntactic priority, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
154 \samp{in}\opindex{in} and \samp{not in}\opindex{not in}, are supported |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
155 only by sequence types (below). |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
156 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
157 |
| 9083 | 158 \subsection{Numeric Types \label{typesnumeric}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
159 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
160 There are four numeric types: \dfn{plain integers}, \dfn{long integers}, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
161 \dfn{floating point numbers}, and \dfn{complex numbers}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
162 Plain integers (also just called \dfn{integers}) |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
163 are implemented using \ctype{long} in C, which gives them at least 32 |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
164 bits of precision. Long integers have unlimited precision. Floating |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
165 point numbers are implemented using \ctype{double} in C. All bets on |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
166 their precision are off unless you happen to know the machine you are |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
167 working with. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
168 \indexii{numeric}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
169 \indexii{integer}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
170 \indexii{integer}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
171 \indexiii{long}{integer}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
172 \indexii{floating point}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
173 \indexii{complex number}{type} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
174 \indexii{C}{language} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
175 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
176 Complex numbers have a real and imaginary part, which are both |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
177 implemented using \ctype{double} in C. To extract these parts from |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
178 a complex number \var{z}, use \code{\var{z}.real} and \code{\var{z}.imag}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
179 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
180 Numbers are created by numeric literals or as the result of built-in |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
181 functions and operators. Unadorned integer literals (including hex |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
182 and octal numbers) yield plain integers. Integer literals with an |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
183 \character{L} or \character{l} suffix yield long integers |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
184 (\character{L} is preferred because \samp{1l} looks too much like |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
185 eleven!). Numeric literals containing a decimal point or an exponent |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
186 sign yield floating point numbers. Appending \character{j} or |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
187 \character{J} to a numeric literal yields a complex number. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
188 \indexii{numeric}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
189 \indexii{integer}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
190 \indexiii{long}{integer}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
191 \indexii{floating point}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
192 \indexii{complex number}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
193 \indexii{hexadecimal}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
194 \indexii{octal}{literals} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
195 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
196 Python fully supports mixed arithmetic: when a binary arithmetic |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
197 operator has operands of different numeric types, the operand with the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
198 ``smaller'' type is converted to that of the other, where plain |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
199 integer is smaller than long integer is smaller than floating point is |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
200 smaller than complex. |
|
10520
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
201 Comparisons between numbers of mixed type use the same rule.\footnote{ |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
202 As a consequence, the list \code{[1, 2]} is considered equal |
| 11100 | 203 to \code{[1.0, 2.0]}, and similar for tuples. |
| 204 } The functions \function{int()}, \function{long()}, \function{float()}, | |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
205 and \function{complex()} can be used |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
206 to coerce numbers to a specific type. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
207 \index{arithmetic} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
208 \bifuncindex{int} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
209 \bifuncindex{long} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
210 \bifuncindex{float} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
211 \bifuncindex{complex} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
212 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
213 All numeric types support the following operations, sorted by |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
214 ascending priority (operations in the same box have the same |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
215 priority; all numeric operations have a higher priority than |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
216 comparison operations): |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
217 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
218 \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
219 \lineiii{\var{x} + \var{y}}{sum of \var{x} and \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
220 \lineiii{\var{x} - \var{y}}{difference of \var{x} and \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
221 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
222 \lineiii{\var{x} * \var{y}}{product of \var{x} and \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
223 \lineiii{\var{x} / \var{y}}{quotient of \var{x} and \var{y}}{(1)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
224 \lineiii{\var{x} \%{} \var{y}}{remainder of \code{\var{x} / \var{y}}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
225 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
226 \lineiii{-\var{x}}{\var{x} negated}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
227 \lineiii{+\var{x}}{\var{x} unchanged}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
228 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
229 \lineiii{abs(\var{x})}{absolute value or magnitude of \var{x}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
230 \lineiii{int(\var{x})}{\var{x} converted to integer}{(2)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
231 \lineiii{long(\var{x})}{\var{x} converted to long integer}{(2)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
232 \lineiii{float(\var{x})}{\var{x} converted to floating point}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
233 \lineiii{complex(\var{re},\var{im})}{a complex number with real part \var{re}, imaginary part \var{im}. \var{im} defaults to zero.}{} |
|
10147
3ac7f0066375
Document <complex #>.conjugate().
Fred Drake <fdrake@acm.org>
parents:
9558
diff
changeset
|
234 \lineiii{\var{c}.conjugate()}{conjugate of the complex number \var{c}}{} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
235 \lineiii{divmod(\var{x}, \var{y})}{the pair \code{(\var{x} / \var{y}, \var{x} \%{} \var{y})}}{(3)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
236 \lineiii{pow(\var{x}, \var{y})}{\var{x} to the power \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
237 \lineiii{\var{x} ** \var{y}}{\var{x} to the power \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
238 \end{tableiii} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
239 \indexiii{operations on}{numeric}{types} |
|
10147
3ac7f0066375
Document <complex #>.conjugate().
Fred Drake <fdrake@acm.org>
parents:
9558
diff
changeset
|
240 \withsubitem{(complex number method)}{\ttindex{conjugate()}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
241 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
242 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
243 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
244 \begin{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
245 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
246 \item[(1)] |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
247 For (plain or long) integer division, the result is an integer. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
248 The result is always rounded towards minus infinity: 1/2 is 0, |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
249 (-1)/2 is -1, 1/(-2) is -1, and (-1)/(-2) is 0. Note that the result |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
250 is a long integer if either operand is a long integer, regardless of |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
251 the numeric value. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
252 \indexii{integer}{division} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
253 \indexiii{long}{integer}{division} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
254 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
255 \item[(2)] |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
256 Conversion from floating point to (long or plain) integer may round or |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
257 truncate as in \C{}; see functions \function{floor()} and \function{ceil()} in |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
258 module \refmodule{math}\refbimodindex{math} for well-defined conversions. |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
259 \withsubitem{(in module math)}{\ttindex{floor()}\ttindex{ceil()}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
260 \indexii{numeric}{conversions} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
261 \indexii{C@\C{}}{language} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
262 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
263 \item[(3)] |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
264 See section \ref{built-in-funcs}, ``Built-in Functions,'' for a full |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
265 description. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
266 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
267 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
268 % XXXJH exceptions: overflow (when? what operations?) zerodivision |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
269 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
270 \subsubsection{Bit-string Operations on Integer Types \label{bitstring-ops}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
271 \nodename{Bit-string Operations} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
272 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
273 Plain and long integer types support additional operations that make |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
274 sense only for bit-strings. Negative numbers are treated as their 2's |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
275 complement value (for long integers, this assumes a sufficiently large |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
276 number of bits that no overflow occurs during the operation). |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
277 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
278 The priorities of the binary bit-wise operations are all lower than |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
279 the numeric operations and higher than the comparisons; the unary |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
280 operation \samp{\~} has the same priority as the other unary numeric |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
281 operations (\samp{+} and \samp{-}). |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
282 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
283 This table lists the bit-string operations sorted in ascending |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
284 priority (operations in the same box have the same priority): |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
285 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
286 \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
287 \lineiii{\var{x} | \var{y}}{bitwise \dfn{or} of \var{x} and \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
288 \lineiii{\var{x} \^{} \var{y}}{bitwise \dfn{exclusive or} of \var{x} and \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
289 \lineiii{\var{x} \&{} \var{y}}{bitwise \dfn{and} of \var{x} and \var{y}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
290 \lineiii{\var{x} << \var{n}}{\var{x} shifted left by \var{n} bits}{(1), (2)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
291 \lineiii{\var{x} >> \var{n}}{\var{x} shifted right by \var{n} bits}{(1), (3)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
292 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
293 \lineiii{\~\var{x}}{the bits of \var{x} inverted}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
294 \end{tableiii} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
295 \indexiii{operations on}{integer}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
296 \indexii{bit-string}{operations} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
297 \indexii{shifting}{operations} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
298 \indexii{masking}{operations} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
299 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
300 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
301 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
302 \begin{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
303 \item[(1)] Negative shift counts are illegal and cause a |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
304 \exception{ValueError} to be raised. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
305 \item[(2)] A left shift by \var{n} bits is equivalent to |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
306 multiplication by \code{pow(2, \var{n})} without overflow check. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
307 \item[(3)] A right shift by \var{n} bits is equivalent to |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
308 division by \code{pow(2, \var{n})} without overflow check. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
309 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
310 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
311 |
| 9083 | 312 \subsection{Sequence Types \label{typesseq}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
313 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
314 There are three sequence types: strings, lists and tuples. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
315 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
316 Strings literals are written in single or double quotes: |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
317 \code{'xyzzy'}, \code{"frobozz"}. See chapter 2 of the |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
318 \citetitle[../ref/ref.html]{Python Reference Manual} for more about |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
319 string literals. Lists are constructed with square brackets, |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
320 separating items with commas: \code{[a, b, c]}. Tuples are |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
321 constructed by the comma operator (not within square brackets), with |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
322 or without enclosing parentheses, but an empty tuple must have the |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
323 enclosing parentheses, e.g., \code{a, b, c} or \code{()}. A single |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
324 item tuple must have a trailing comma, e.g., \code{(d,)}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
325 \indexii{sequence}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
326 \indexii{string}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
327 \indexii{tuple}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
328 \indexii{list}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
329 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
330 Sequence types support the following operations. The \samp{in} and |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
331 \samp{not in} operations have the same priorities as the comparison |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
332 operations. The \samp{+} and \samp{*} operations have the same |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
333 priority as the corresponding numeric operations.\footnote{They must |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
334 have since the parser can't tell the type of the operands.} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
335 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
336 This table lists the sequence operations sorted in ascending priority |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
337 (operations in the same box have the same priority). In the table, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
338 \var{s} and \var{t} are sequences of the same type; \var{n}, \var{i} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
339 and \var{j} are integers: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
340 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
341 \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
342 \lineiii{\var{x} in \var{s}}{\code{1} if an item of \var{s} is equal to \var{x}, else \code{0}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
343 \lineiii{\var{x} not in \var{s}}{\code{0} if an item of \var{s} is |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
344 equal to \var{x}, else \code{1}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
345 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
346 \lineiii{\var{s} + \var{t}}{the concatenation of \var{s} and \var{t}}{} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
347 \lineiii{\var{s} * \var{n}\textrm{,} \var{n} * \var{s}}{\var{n} copies of \var{s} concatenated}{(1)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
348 \hline |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
349 \lineiii{\var{s}[\var{i}]}{\var{i}'th item of \var{s}, origin 0}{(2)} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
350 \lineiii{\var{s}[\var{i}:\var{j}]}{slice of \var{s} from \var{i} to \var{j}}{(2), (3)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
351 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
352 \lineiii{len(\var{s})}{length of \var{s}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
353 \lineiii{min(\var{s})}{smallest item of \var{s}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
354 \lineiii{max(\var{s})}{largest item of \var{s}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
355 \end{tableiii} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
356 \indexiii{operations on}{sequence}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
357 \bifuncindex{len} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
358 \bifuncindex{min} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
359 \bifuncindex{max} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
360 \indexii{concatenation}{operation} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
361 \indexii{repetition}{operation} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
362 \indexii{subscript}{operation} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
363 \indexii{slice}{operation} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
364 \opindex{in} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
365 \opindex{not in} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
366 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
367 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
368 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
369 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
370 \begin{description} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
371 \item[(1)] Values of \var{n} less than \code{0} are treated as |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
372 \code{0} (which yields an empty sequence of the same type as |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
373 \var{s}). |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
374 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
375 \item[(2)] If \var{i} or \var{j} is negative, the index is relative to |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
376 the end of the string, i.e., \code{len(\var{s}) + \var{i}} or |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
377 \code{len(\var{s}) + \var{j}} is substituted. But note that \code{-0} is |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
378 still \code{0}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
379 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
380 \item[(3)] The slice of \var{s} from \var{i} to \var{j} is defined as |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
381 the sequence of items with index \var{k} such that \code{\var{i} <= |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
382 \var{k} < \var{j}}. If \var{i} or \var{j} is greater than |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
383 \code{len(\var{s})}, use \code{len(\var{s})}. If \var{i} is omitted, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
384 use \code{0}. If \var{j} is omitted, use \code{len(\var{s})}. If |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
385 \var{i} is greater than or equal to \var{j}, the slice is empty. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
386 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
387 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
388 |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
389 \subsubsection{More String Operations \label{typesseq-strings}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
390 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
391 String objects have one unique built-in operation: the \code{\%} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
392 operator (modulo) with a string left argument interprets this string |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
393 as a \C{} \cfunction{sprintf()} format string to be applied to the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
394 right argument, and returns the string resulting from this formatting |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
395 operation. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
396 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
397 The right argument should be a tuple with one item for each argument |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
398 required by the format string; if the string requires a single |
|
10520
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
399 argument, the right argument may also be a single non-tuple |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
400 object.\footnote{A tuple object in this case should be a singleton.} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
401 The following format characters are understood: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
402 \code{\%}, \code{c}, \code{s}, \code{i}, \code{d}, \code{u}, \code{o}, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
403 \code{x}, \code{X}, \code{e}, \code{E}, \code{f}, \code{g}, \code{G}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
404 Width and precision may be a \code{*} to specify that an integer argument |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
405 specifies the actual width or precision. The flag characters |
|
10662
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
406 \code{-}, \code{+}, blank, \code{\#} and \code{0} are understood. The |
|
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
407 size specifiers \code{h}, \code{l} or \code{L} may be present but are |
|
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
408 ignored. The \code{\%s} conversion takes any Python object and |
|
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
409 converts it to a string using \code{str()} before formatting it. The |
|
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
410 ANSI features \code{\%p} and \code{\%n} are not supported. Since |
|
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
411 Python strings have an explicit length, \code{\%s} conversions don't |
|
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
412 assume that \code{'\e0'} is the end of the string. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
413 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
414 For safety reasons, floating point precisions are clipped to 50; |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
415 \code{\%f} conversions for numbers whose absolute value is over 1e25 |
|
10520
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
416 are replaced by \code{\%g} conversions.\footnote{ |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
417 These numbers are fairly arbitrary. They are intended to |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
418 avoid printing endless strings of meaningless digits without hampering |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
419 correct use and without having to know the exact precision of floating |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
420 point values on a particular machine.} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
421 All other errors raise exceptions. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
422 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
423 If the right argument is a dictionary (or any kind of mapping), then |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
424 the formats in the string must have a parenthesized key into that |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
425 dictionary inserted immediately after the \character{\%} character, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
426 and each format formats the corresponding entry from the mapping. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
427 For example: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
428 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
429 \begin{verbatim} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
430 >>> count = 2 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
431 >>> language = 'Python' |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
432 >>> print '%(language)s has %(count)03d quote types.' % vars() |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
433 Python has 002 quote types. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
434 \end{verbatim} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
435 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
436 In this case no \code{*} specifiers may occur in a format (since they |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
437 require a sequential parameter list). |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
438 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
439 Additional string operations are defined in standard module |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
440 \module{string} and in built-in module \module{re}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
441 \refstmodindex{string} |
| 8882 | 442 \refstmodindex{re} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
443 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
444 \subsubsection{Mutable Sequence Types \label{typesseq-mutable}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
445 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
446 List objects support additional operations that allow in-place |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
447 modification of the object. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
448 These operations would be supported by other mutable sequence types |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
449 (when added to the language) as well. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
450 Strings and tuples are immutable sequence types and such objects cannot |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
451 be modified once created. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
452 The following operations are defined on mutable sequence types (where |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
453 \var{x} is an arbitrary object): |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
454 \indexiii{mutable}{sequence}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
455 \indexii{list}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
456 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
457 \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
458 \lineiii{\var{s}[\var{i}] = \var{x}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
459 {item \var{i} of \var{s} is replaced by \var{x}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
460 \lineiii{\var{s}[\var{i}:\var{j}] = \var{t}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
461 {slice of \var{s} from \var{i} to \var{j} is replaced by \var{t}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
462 \lineiii{del \var{s}[\var{i}:\var{j}]} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
463 {same as \code{\var{s}[\var{i}:\var{j}] = []}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
464 \lineiii{\var{s}.append(\var{x})} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
465 {same as \code{\var{s}[len(\var{s}):len(\var{s})] = [\var{x}]}}{(1)} |
|
9318
8a26e55e18b8
Document the new list.extend() method. Interesting enough, the
Barry Warsaw <barry@python.org>
parents:
9083
diff
changeset
|
466 \lineiii{\var{s}.extend(\var{x})} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
467 {same as \code{\var{s}[len(\var{s}):len(\var{s})] = \var{x}}}{(2)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
468 \lineiii{\var{s}.count(\var{x})} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
469 {return number of \var{i}'s for which \code{\var{s}[\var{i}] == \var{x}}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
470 \lineiii{\var{s}.index(\var{x})} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
471 {return smallest \var{i} such that \code{\var{s}[\var{i}] == \var{x}}}{(3)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
472 \lineiii{\var{s}.insert(\var{i}, \var{x})} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
473 {same as \code{\var{s}[\var{i}:\var{i}] = [\var{x}]} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
474 if \code{\var{i} >= 0}}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
475 \lineiii{\var{s}.pop(\optional{\var{i}})} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
476 {same as \code{\var{x} = \var{s}[\var{i}]; del \var{s}[\var{i}]; return \var{x}}}{(4)} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
477 \lineiii{\var{s}.remove(\var{x})} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
478 {same as \code{del \var{s}[\var{s}.index(\var{x})]}}{(3)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
479 \lineiii{\var{s}.reverse()} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
480 {reverses the items of \var{s} in place}{(5)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
481 \lineiii{\var{s}.sort(\optional{\var{cmpfunc}})} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
482 {sort the items of \var{s} in place}{(5), (6)} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
483 \end{tableiii} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
484 \indexiv{operations on}{mutable}{sequence}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
485 \indexiii{operations on}{sequence}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
486 \indexiii{operations on}{list}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
487 \indexii{subscript}{assignment} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
488 \indexii{slice}{assignment} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
489 \stindex{del} |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
490 \withsubitem{(list method)}{ |
|
11183
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
491 \ttindex{append()}\ttindex{extend()}\ttindex{count()}\ttindex{index()} |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
492 \ttindex{insert()}\ttindex{pop()}\ttindex{remove()}\ttindex{reverse()} |
|
9523
ed6cacddc6c6
Fix indexing of func_code attribute; this is on a function, not a code
Fred Drake <fdrake@acm.org>
parents:
9461
diff
changeset
|
493 \ttindex{sort()}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
494 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
495 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
496 \begin{description} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
497 \item[(1)] The C implementation of Python has historically accepted |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
498 multiple parameters and implicitly joined them into a tuple; this |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
499 will no longer work in Python 1.6. Use of this misfeature has been |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
500 deprecated since Python 1.4. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
501 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
502 \item[(2)] Raises an exception when \var{x} is not a list object. The |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
503 \method{extend()} method is experimental and not supported by |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
504 mutable sequence types other than lists. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
505 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
506 \item[(3)] Raises \exception{ValueError} when \var{x} is not found in |
|
11183
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
507 \var{s}. |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
508 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
509 \item[(4)] The \method{pop()} method is experimental and not supported |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
510 by other mutable sequence types than lists. The optional argument |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
511 \var{i} defaults to \code{-1}, so that by default the last item is |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
512 removed and returned. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
513 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
514 \item[(5)] The \method{sort()} and \method{reverse()} methods modify the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
515 list in place for economy of space when sorting or reversing a large |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
516 list. They don't return the sorted or reversed list to remind you |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
517 of this side effect. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
518 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
519 \item[(6)] The \method{sort()} method takes an optional argument |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
520 specifying a comparison function of two arguments (list items) which |
|
11183
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
521 should return \code{-1}, \code{0} or \code{1} depending on whether |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
522 the first argument is considered smaller than, equal to, or larger |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
523 than the second argument. Note that this slows the sorting process |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
524 down considerably; e.g. to sort a list in reverse order it is much |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
525 faster to use calls to the methods \method{sort()} and |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
526 \method{reverse()} than to use the built-in function |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
527 \function{sort()} with a comparison function that reverses the |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
528 ordering of the elements. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
529 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
530 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
531 |
| 9083 | 532 \subsection{Mapping Types \label{typesmapping}} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
533 \indexii{mapping}{types} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
534 \indexii{dictionary}{type} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
535 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
536 A \dfn{mapping} object maps values of one type (the key type) to |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
537 arbitrary objects. Mappings are mutable objects. There is currently |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
538 only one standard mapping type, the \dfn{dictionary}. A dictionary's keys are |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
539 almost arbitrary values. The only types of values not acceptable as |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
540 keys are values containing lists or dictionaries or other mutable |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
541 types that are compared by value rather than by object identity. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
542 Numeric types used for keys obey the normal rules for numeric |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
543 comparison: if two numbers compare equal (e.g. \code{1} and |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
544 \code{1.0}) then they can be used interchangeably to index the same |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
545 dictionary entry. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
546 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
547 Dictionaries are created by placing a comma-separated list of |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
548 \code{\var{key}: \var{value}} pairs within braces, for example: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
549 \code{\{'jack': 4098, 'sjoerd': 4127\}} or |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
550 \code{\{4098: 'jack', 4127: 'sjoerd'\}}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
551 |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
552 The following operations are defined on mappings (where \var{a} and |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
553 \var{b} are mappings, \var{k} is a key, and \var{v} and \var{x} are |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
554 arbitrary objects): |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
555 \indexiii{operations on}{mapping}{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
556 \indexiii{operations on}{dictionary}{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
557 \stindex{del} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
558 \bifuncindex{len} |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
559 \withsubitem{(dictionary method)}{ |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
560 \ttindex{clear()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
561 \ttindex{copy()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
562 \ttindex{has_key()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
563 \ttindex{items()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
564 \ttindex{keys()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
565 \ttindex{update()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
566 \ttindex{values()} |
|
9523
ed6cacddc6c6
Fix indexing of func_code attribute; this is on a function, not a code
Fred Drake <fdrake@acm.org>
parents:
9461
diff
changeset
|
567 \ttindex{get()}} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
568 |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
569 \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
570 \lineiii{len(\var{a})}{the number of items in \var{a}}{} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
571 \lineiii{\var{a}[\var{k}]}{the item of \var{a} with key \var{k}}{(1)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
572 \lineiii{\var{a}[\var{k}] = \var{x}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
573 {set \code{\var{a}[\var{k}]} to \var{x}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
574 {} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
575 \lineiii{del \var{a}[\var{k}]} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
576 {remove \code{\var{a}[\var{k}]} from \var{a}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
577 {(1)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
578 \lineiii{\var{a}.clear()}{remove all items from \code{a}}{} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
579 \lineiii{\var{a}.copy()}{a (shallow) copy of \code{a}}{} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
580 \lineiii{\var{a}.has_key(\var{k})} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
581 {\code{1} if \var{a} has a key \var{k}, else \code{0}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
582 {} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
583 \lineiii{\var{a}.items()} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
584 {a copy of \var{a}'s list of (\var{key}, \var{value}) pairs} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
585 {(2)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
586 \lineiii{\var{a}.keys()}{a copy of \var{a}'s list of keys}{(2)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
587 \lineiii{\var{a}.update(\var{b})} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
588 {\code{for k, v in \var{b}.items(): \var{a}[k] = v}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
589 {(3)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
590 \lineiii{\var{a}.values()}{a copy of \var{a}'s list of values}{(2)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
591 \lineiii{\var{a}.get(\var{k}\optional{, \var{x}})} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
592 {\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})}, |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
593 else \var{x}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
594 {(4)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
595 \end{tableiii} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
596 |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
597 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
598 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
599 \begin{description} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
600 \item[(1)] Raises a \exception{KeyError} exception if \var{k} is not |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
601 in the map. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
602 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
603 \item[(2)] Keys and values are listed in random order. If |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
604 \method{keys()} and \method{values()} are called with no intervening |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
605 modifications to the dictionary, the two lists will directly |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
606 correspond. This allows the creation of \code{(\var{value}, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
607 \var{key})} pairs using \function{map()}: \samp{pairs = map(None, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
608 \var{a}.values(), \var{a}.keys())}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
609 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
610 \item[(3)] \var{b} must be of the same type as \var{a}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
611 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
612 \item[(4)] Never raises an exception if \var{k} is not in the map, |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
613 instead it returns \var{x}. \var{x} is optional; when \var{x} is not |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
614 provided and \var{k} is not in the map, \code{None} is returned. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
615 \end{description} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
616 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
617 |
| 9083 | 618 \subsection{Other Built-in Types \label{typesother}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
619 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
620 The interpreter supports several other kinds of objects. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
621 Most of these support only one or two operations. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
622 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
623 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
624 \subsubsection{Modules \label{typesmodules}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
625 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
626 The only special operation on a module is attribute access: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
627 \code{\var{m}.\var{name}}, where \var{m} is a module and \var{name} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
628 accesses a name defined in \var{m}'s symbol table. Module attributes |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
629 can be assigned to. (Note that the \keyword{import} statement is not, |
| 9034 | 630 strictly speaking, an operation on a module object; \code{import |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
631 \var{foo}} does not require a module object named \var{foo} to exist, |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
632 rather it requires an (external) \emph{definition} for a module named |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
633 \var{foo} somewhere.) |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
634 |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
635 A special member of every module is \member{__dict__}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
636 This is the dictionary containing the module's symbol table. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
637 Modifying this dictionary will actually change the module's symbol |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
638 table, but direct assignment to the \member{__dict__} attribute is not |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
639 possible (i.e., you can write \code{\var{m}.__dict__['a'] = 1}, which |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
640 defines \code{\var{m}.a} to be \code{1}, but you can't write |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
641 \code{\var{m}.__dict__ = \{\}}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
642 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
643 Modules built into the interpreter are written like this: |
|
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
644 \code{<module 'sys' (built-in)>}. If loaded from a file, they are |
|
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
645 written as \code{<module 'os' from '/usr/local/lib/python1.5/os.pyc'>}. |
|
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
646 |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
647 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
648 \subsubsection{Classes and Class Instances \label{typesobjects}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
649 \nodename{Classes and Instances} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
650 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
651 See chapters 3 and 7 of the \citetitle[../ref/ref.html]{Python |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
652 Reference Manual} for these. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
653 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
654 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
655 \subsubsection{Functions \label{typesfunctions}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
656 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
657 Function objects are created by function definitions. The only |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
658 operation on a function object is to call it: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
659 \code{\var{func}(\var{argument-list})}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
660 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
661 There are really two flavors of function objects: built-in functions |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
662 and user-defined functions. Both support the same operation (to call |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
663 the function), but the implementation is different, hence the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
664 different object types. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
665 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
666 The implementation adds two special read-only attributes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
667 \code{\var{f}.func_code} is a function's \dfn{code |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
668 object}\obindex{code} (see below) and \code{\var{f}.func_globals} is |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
669 the dictionary used as the function's global name space (this is the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
670 same as \code{\var{m}.__dict__} where \var{m} is the module in which |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
671 the function \var{f} was defined). |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
672 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
673 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
674 \subsubsection{Methods \label{typesmethods}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
675 \obindex{method} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
676 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
677 Methods are functions that are called using the attribute notation. |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
678 There are two flavors: built-in methods (such as \method{append()} on |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
679 lists) and class instance methods. Built-in methods are described |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
680 with the types that support them. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
681 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
682 The implementation adds two special read-only attributes to class |
| 9034 | 683 instance methods: \code{\var{m}.im_self} is the object on which the |
| 684 method operates, and \code{\var{m}.im_func} is the function | |
| 685 implementing the method. Calling \code{\var{m}(\var{arg-1}, | |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
686 \var{arg-2}, \textrm{\ldots}, \var{arg-n})} is completely equivalent to |
| 9034 | 687 calling \code{\var{m}.im_func(\var{m}.im_self, \var{arg-1}, |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
688 \var{arg-2}, \textrm{\ldots}, \var{arg-n})}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
689 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
690 See the \citetitle[../ref/ref.html]{Python Reference Manual} for more |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
691 information. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
692 |
| 9083 | 693 |
| 694 \subsubsection{Code Objects \label{bltin-code-objects}} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
695 \obindex{code} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
696 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
697 Code objects are used by the implementation to represent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
698 ``pseudo-compiled'' executable Python code such as a function body. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
699 They differ from function objects because they don't contain a |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
700 reference to their global execution environment. Code objects are |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
701 returned by the built-in \function{compile()} function and can be |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
702 extracted from function objects through their \member{func_code} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
703 attribute. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
704 \bifuncindex{compile} |
|
9523
ed6cacddc6c6
Fix indexing of func_code attribute; this is on a function, not a code
Fred Drake <fdrake@acm.org>
parents:
9461
diff
changeset
|
705 \withsubitem{(function object attribute)}{\ttindex{func_code}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
706 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
707 A code object can be executed or evaluated by passing it (instead of a |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
708 source string) to the \keyword{exec} statement or the built-in |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
709 \function{eval()} function. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
710 \stindex{exec} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
711 \bifuncindex{eval} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
712 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
713 See the \citetitle[../ref/ref.html]{Python Reference Manual} for more |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
714 information. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
715 |
| 9083 | 716 |
| 717 \subsubsection{Type Objects \label{bltin-type-objects}} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
718 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
719 Type objects represent the various object types. An object's type is |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
720 accessed by the built-in function \function{type()}. There are no special |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
721 operations on types. The standard module \module{types} defines names |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
722 for all standard built-in types. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
723 \bifuncindex{type} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
724 \refstmodindex{types} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
725 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
726 Types are written like this: \code{<type 'int'>}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
727 |
| 9083 | 728 |
| 729 \subsubsection{The Null Object \label{bltin-null-object}} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
730 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
731 This object is returned by functions that don't explicitly return a |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
732 value. It supports no special operations. There is exactly one null |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
733 object, named \code{None} (a built-in name). |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
734 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
735 It is written as \code{None}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
736 |
| 9083 | 737 |
| 738 \subsubsection{The Ellipsis Object \label{bltin-ellipsis-object}} | |
|
8734
ddaac06ec326
Document Ellipsis (not much of a documentation snippet, but at least
Guido van Rossum <guido@python.org>
parents:
8730
diff
changeset
|
739 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
740 This object is used by extended slice notation (see the |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
741 \citetitle[../ref/ref.html]{Python Reference Manual}). It supports no |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
742 special operations. There is exactly one ellipsis object, named |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
743 \constant{Ellipsis} (a built-in name). |
|
8734
ddaac06ec326
Document Ellipsis (not much of a documentation snippet, but at least
Guido van Rossum <guido@python.org>
parents:
8730
diff
changeset
|
744 |
|
ddaac06ec326
Document Ellipsis (not much of a documentation snippet, but at least
Guido van Rossum <guido@python.org>
parents:
8730
diff
changeset
|
745 It is written as \code{Ellipsis}. |
|
ddaac06ec326
Document Ellipsis (not much of a documentation snippet, but at least
Guido van Rossum <guido@python.org>
parents:
8730
diff
changeset
|
746 |
|
10636
9fd29021d147
Added index entry for "file objects"; this is appearantly referenced
Fred Drake <fdrake@acm.org>
parents:
10606
diff
changeset
|
747 \subsubsection{File Objects\obindex{file} |
|
9fd29021d147
Added index entry for "file objects"; this is appearantly referenced
Fred Drake <fdrake@acm.org>
parents:
10606
diff
changeset
|
748 \label{bltin-file-objects}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
749 |
|
10636
9fd29021d147
Added index entry for "file objects"; this is appearantly referenced
Fred Drake <fdrake@acm.org>
parents:
10606
diff
changeset
|
750 File objects are implemented using \C{}'s \code{stdio} |
|
9fd29021d147
Added index entry for "file objects"; this is appearantly referenced
Fred Drake <fdrake@acm.org>
parents:
10606
diff
changeset
|
751 package and can be created with the built-in function |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
752 \function{open()}\bifuncindex{open} described in section |
|
9461
9ffd604807c2
Don't describe something as "below"; that won't make sense for the
Fred Drake <fdrake@acm.org>
parents:
9318
diff
changeset
|
753 \ref{built-in-funcs}, ``Built-in Functions.'' They are also returned |
|
9ffd604807c2
Don't describe something as "below"; that won't make sense for the
Fred Drake <fdrake@acm.org>
parents:
9318
diff
changeset
|
754 by some other built-in functions and methods, e.g., |
|
9ffd604807c2
Don't describe something as "below"; that won't make sense for the
Fred Drake <fdrake@acm.org>
parents:
9318
diff
changeset
|
755 \function{posix.popen()} and \function{posix.fdopen()} and the |
|
9ffd604807c2
Don't describe something as "below"; that won't make sense for the
Fred Drake <fdrake@acm.org>
parents:
9318
diff
changeset
|
756 \method{makefile()} method of socket objects. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
757 \refbimodindex{posix} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
758 \refbimodindex{socket} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
759 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
760 When a file operation fails for an I/O-related reason, the exception |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
761 \exception{IOError} is raised. This includes situations where the |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
762 operation is not defined for some reason, like \method{seek()} on a tty |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
763 device or writing a file opened for reading. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
764 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
765 Files have the following methods: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
766 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
767 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
768 \begin{methoddesc}[file]{close}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
769 Close the file. A closed file cannot be read or written anymore. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
770 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
771 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
772 \begin{methoddesc}[file]{flush}{} |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
773 Flush the internal buffer, like \code{stdio}'s \cfunction{fflush()}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
774 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
775 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
776 \begin{methoddesc}[file]{isatty}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
777 Return \code{1} if the file is connected to a tty(-like) device, else |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
778 \code{0}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
779 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
780 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
781 \begin{methoddesc}[file]{fileno}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
782 Return the integer ``file descriptor'' that is used by the underlying |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
783 implementation to request I/O operations from the operating system. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
784 This can be useful for other, lower level interfaces that use file |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
785 descriptors, e.g. module \module{fcntl} or \function{os.read()} and friends. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
786 \refbimodindex{fcntl} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
787 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
788 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
789 \begin{methoddesc}[file]{read}{\optional{size}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
790 Read at most \var{size} bytes from the file (less if the read hits |
|
10606
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
791 \EOF{} before obtaining \var{size} bytes). If the \var{size} |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
792 argument is negative or omitted, read all data until \EOF{} is |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
793 reached. The bytes are returned as a string object. An empty |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
794 string is returned when \EOF{} is encountered immediately. (For |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
795 certain files, like ttys, it makes sense to continue reading after |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
796 an \EOF{} is hit.) Note that this method may call the underlying |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
797 C function \cfunction{fread()} more than once in an effort to |
|
fe5fcb7e73f7
Correct documentation for <file>.read(); Python makes a serious
Fred Drake <fdrake@acm.org>
parents:
10520
diff
changeset
|
798 acquire as close to \var{size} bytes as possible. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
799 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
800 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
801 \begin{methoddesc}[file]{readline}{\optional{size}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
802 Read one entire line from the file. A trailing newline character is |
|
10520
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
803 kept in the string\footnote{ |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
804 The advantage of leaving the newline on is that an empty string |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
805 can be returned to mean \EOF{} without being ambiguous. Another |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
806 advantage is that (in cases where it might matter, e.g. if you |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
807 want to make an exact copy of a file while scanning its lines) |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
808 you can tell whether the last line of a file ended in a newline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
809 or not (yes this happens!).} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
810 (but may be absent when a file ends with an |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
811 incomplete line). If the \var{size} argument is present and |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
812 non-negative, it is a maximum byte count (including the trailing |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
813 newline) and an incomplete line may be returned. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
814 An empty string is returned when \EOF{} is hit |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
815 immediately. Note: Unlike \code{stdio}'s \cfunction{fgets()}, the returned |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
816 string contains null characters (\code{'\e 0'}) if they occurred in the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
817 input. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
818 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
819 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
820 \begin{methoddesc}[file]{readlines}{\optional{sizehint}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
821 Read until \EOF{} using \method{readline()} and return a list containing |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
822 the lines thus read. If the optional \var{sizehint} argument is |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
823 present, instead of reading up to \EOF{}, whole lines totalling |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
824 approximately \var{sizehint} bytes (possibly after rounding up to an |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
825 internal buffer size) are read. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
826 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
827 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
828 \begin{methoddesc}[file]{seek}{offset\optional{, whence}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
829 Set the file's current position, like \code{stdio}'s \cfunction{fseek()}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
830 The \var{whence} argument is optional and defaults to \code{0} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
831 (absolute file positioning); other values are \code{1} (seek |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
832 relative to the current position) and \code{2} (seek relative to the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
833 file's end). There is no return value. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
834 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
835 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
836 \begin{methoddesc}[file]{tell}{} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
837 Return the file's current position, like \code{stdio}'s |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
838 \cfunction{ftell()}. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
839 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
840 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
841 \begin{methoddesc}[file]{truncate}{\optional{size}} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
842 Truncate the file's size. If the optional size argument present, the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
843 file is truncated to (at most) that size. The size defaults to the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
844 current position. Availability of this function depends on the |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
845 operating system version (for example, not all \UNIX{} versions support this |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
846 operation). |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
847 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
848 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
849 \begin{methoddesc}[file]{write}{str} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
850 Write a string to the file. There is no return value. Note: Due to |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
851 buffering, the string may not actually show up in the file until |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
852 the \method{flush()} or \method{close()} method is called. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
853 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
854 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
855 \begin{methoddesc}[file]{writelines}{list} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
856 Write a list of strings to the file. There is no return value. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
857 (The name is intended to match \method{readlines()}; |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
858 \method{writelines()} does not add line separators.) |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
859 \end{methoddesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
860 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
861 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
862 File objects also offer the following attributes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
863 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
864 \begin{memberdesc}[file]{closed} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
865 Boolean indicating the current state of the file object. This is a |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
866 read-only attribute; the \method{close()} method changes the value. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
867 \end{memberdesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
868 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
869 \begin{memberdesc}[file]{mode} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
870 The I/O mode for the file. If the file was created using the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
871 \function{open()} built-in function, this will be the value of the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
872 \var{mode} parameter. This is a read-only attribute. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
873 \end{memberdesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
874 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
875 \begin{memberdesc}[file]{name} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
876 If the file object was created using \function{open()}, the name of |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
877 the file. Otherwise, some string that indicates the source of the |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
878 file object, of the form \samp{<\mbox{\ldots}>}. This is a read-only |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
879 attribute. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
880 \end{memberdesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
881 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
882 \begin{memberdesc}[file]{softspace} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
883 Boolean that indicates whether a space character needs to be printed |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
884 before another value when using the \keyword{print} statement. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
885 Classes that are trying to simulate a file object should also have a |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
886 writable \member{softspace} attribute, which should be initialized to |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
887 zero. This will be automatic for classes implemented in Python; types |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
888 implemented in \C{} will have to provide a writable \member{softspace} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
889 attribute. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
890 \end{memberdesc} |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
891 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
892 \subsubsection{Internal Objects \label{typesinternal}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
893 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
894 See the \citetitle[../ref/ref.html]{Python Reference Manual} for this |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
895 information. It describes code objects, stack frame objects, |
|
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
896 traceback objects, and slice objects. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
897 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
898 |
| 9083 | 899 \subsection{Special Attributes \label{specialattrs}} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
900 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
901 The implementation adds a few special read-only attributes to several |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
902 object types, where they are relevant: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
903 |
| 9083 | 904 \begin{memberdescni}{__dict__} |
| 905 A dictionary of some sort used to store an | |
| 906 object's (writable) attributes. | |
| 907 \end{memberdescni} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
908 |
| 9083 | 909 \begin{memberdescni}{__methods__} |
| 910 List of the methods of many built-in object types, | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
911 e.g., \code{[].__methods__} yields |
| 9083 | 912 \code{['append', 'count', 'index', 'insert', 'pop', 'remove', |
| 913 'reverse', 'sort']}. | |
| 914 \end{memberdescni} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
915 |
| 9083 | 916 \begin{memberdescni}{__members__} |
| 917 Similar to \member{__methods__}, but lists data attributes. | |
| 918 \end{memberdescni} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
919 |
| 9083 | 920 \begin{memberdescni}{__class__} |
| 921 The class to which a class instance belongs. | |
| 922 \end{memberdescni} | |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
923 |
| 9083 | 924 \begin{memberdescni}{__bases__} |
| 925 The tuple of base classes of a class object. | |
| 926 \end{memberdescni} |
