Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libstdtypes.tex @ 15463:aaa91ed3fcfd legacy-trunk
Backing out my changes.
Improved version coming soon to a Source Forge near you!
| author | Moshe Zadka <moshez@math.huji.ac.il> |
|---|---|
| date | Thu, 30 Nov 2000 19:30:21 +0000 |
| parents | 9f775e249ba1 |
| children | aaa54752e4ba |
| 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 |
|
14485
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
43 special methods may be found in the \citetitle[../ref/ref.html]{Python |
|
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
44 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
|
45 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 \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
|
47 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 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
|
49 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
|
50 \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
|
51 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 \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
|
56 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
|
57 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 |
| 9083 | 59 \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
|
60 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
61 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
|
62 \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
|
63 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 \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
|
65 \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
|
66 \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
|
67 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
68 \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
|
69 \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
|
70 \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
|
71 \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
|
72 \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
|
73 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
74 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
75 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
76 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
77 \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
|
78 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 \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
|
80 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
|
81 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
82 \item[(2)] |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
83 \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
|
84 \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
|
85 \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
|
86 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
87 \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
|
88 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 |
| 9083 | 90 \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
|
91 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 \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
|
96 \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
|
97 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
|
98 \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
|
99 \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
|
100 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
101 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
|
102 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
103 \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
|
104 \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
|
105 \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
|
106 \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
|
107 \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
|
108 \lineiii{==}{equal}{} |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
109 \lineiii{!=}{not equal}{(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
|
110 \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
|
111 \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
|
112 \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
|
113 \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
|
114 \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
|
115 \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
|
116 \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
|
117 \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
|
118 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 \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
|
123 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
124 \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
|
125 \code{<>} and \code{!=} are alternate spellings for the same operator. |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
126 (I couldn't choose between \ABC{} and 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
|
127 \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
|
128 \index{language!ABC@\ABC{}} |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
129 \indexii{C}{language} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
130 \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
|
131 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
132 \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
|
133 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
134 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
|
135 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
|
136 (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
|
137 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
|
138 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
|
139 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
|
140 consistently. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
141 \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
|
142 \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
|
143 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
144 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
|
145 \withsubitem{(instance method)}{\ttindex{__cmp__()}} |
|
14485
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
146 defines the \method{__cmp__()} method. Refer to the |
|
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
147 \citetitle[../ref/customization.html]{Python Reference Manual} for |
|
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
148 information on the use of this method to effect 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
|
149 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
150 \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
|
151 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
|
152 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
|
153 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
154 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
|
155 \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
|
156 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
|
157 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
158 |
| 9083 | 159 \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
|
160 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
161 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
|
162 \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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 working with. |
|
15005
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
169 \obindex{numeric} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
170 \obindex{integer} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
171 \obindex{long integer} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
172 \obindex{floating point} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
173 \obindex{complex number} |
|
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 |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
257 truncate as in C; see functions \function{floor()} and |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
258 \function{ceil()} in the \refmodule{math}\refbimodindex{math} module |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
259 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
|
260 \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
|
261 \indexii{numeric}{conversions} |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
262 \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
|
263 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
264 \item[(3)] |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
265 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
|
266 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
|
267 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
268 \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
|
269 % 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
|
270 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
271 \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
|
272 \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
|
273 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 |
|
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 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
|
280 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
|
281 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
|
282 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
|
283 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
284 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
|
285 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
|
286 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
287 \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
|
288 \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
|
289 \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
|
290 \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
|
291 \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
|
292 \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
|
293 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
294 \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
|
295 \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
|
296 \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
|
297 \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
|
298 \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
|
299 \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
|
300 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
301 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
302 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
303 \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
|
304 \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
|
305 \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
|
306 \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
|
307 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
|
308 \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
|
309 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
|
310 \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
|
311 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
312 |
| 9083 | 313 \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
|
314 |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
315 There are six sequence types: strings, Unicode strings, lists, |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
316 tuples, buffers, and xrange 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
|
317 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
318 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
|
319 \code{'xyzzy'}, \code{"frobozz"}. See chapter 2 of the |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
320 \citetitle[../ref/strings.html]{Python Reference Manual} for more about |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
321 string literals. Unicode strings are much like strings, but are |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
322 specified in the syntax using a preceeding \character{u} character: |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
323 \code{u'abc'}, \code{u"def"}. Lists are constructed with square brackets, |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 enclosing parentheses, e.g., \code{a, b, c} or \code{()}. A single |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
328 item tuple must have a trailing comma, e.g., \code{(d,)}. Buffers are |
|
14710
ac6df0494c58
Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents:
14705
diff
changeset
|
329 not directly supported by Python syntax, but can be created by calling the |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
330 builtin function \function{buffer()}.\bifuncindex{buffer} XRanges |
|
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
331 objects are similar to buffers in that there is no specific syntax to |
|
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
332 create them, but they are created using the \function{xrange()} |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
333 function.\bifuncindex{xrange} |
|
15005
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
334 \obindex{sequence} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
335 \obindex{string} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
336 \obindex{Unicode} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
337 \obindex{buffer} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
338 \obindex{tuple} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
339 \obindex{list} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
340 \obindex{xrange} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
341 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
342 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
|
343 \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
|
344 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
|
345 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
|
346 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
|
347 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
348 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
|
349 (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
|
350 \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
|
351 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
|
352 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
353 \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
|
354 \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
|
355 \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
|
356 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
|
357 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
358 \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
|
359 \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
|
360 \hline |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
361 \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
|
362 \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
|
363 \hline |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
364 \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
|
365 \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
|
366 \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
|
367 \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
|
368 \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
|
369 \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
|
370 \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
|
371 \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
|
372 \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
|
373 \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
|
374 \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
|
375 \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
|
376 \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
|
377 \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
|
378 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
379 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
380 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
381 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
382 \begin{description} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
383 \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
|
384 \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
|
385 \var{s}). |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
386 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
387 \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
|
388 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
|
389 \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
|
390 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
|
391 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
392 \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
|
393 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
|
394 \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
|
395 \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
|
396 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
|
397 \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
|
398 \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
|
399 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
400 |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
401 \subsubsection{String Methods \label{string-methods}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
402 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
403 These are the string methods which both 8-bit strings and Unicode |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
404 objects support: |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
405 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
406 \begin{methoddesc}[string]{capitalize}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
407 Return a copy of the string with only its first character capitalized. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
408 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
409 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
410 \begin{methoddesc}[string]{center}{width} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
411 Return centered in a string of length \var{width}. Padding is done |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
412 using spaces. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
413 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
414 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
415 \begin{methoddesc}[string]{count}{sub\optional{, start\optional{, end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
416 Return the number of occurrences of substring \var{sub} in string |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
417 S\code{[\var{start}:\var{end}]}. Optional arguments \var{start} and |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
418 \var{end} are interpreted as in slice notation. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
419 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
420 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
421 \begin{methoddesc}[string]{encode}{\optional{encoding\optional{,errors}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
422 Return an encoded version of the string. Default encoding is the current |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
423 default string encoding. \var{errors} may be given to set a different |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
424 error handling scheme. The default for \var{errors} is |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
425 \code{'strict'}, meaning that encoding errors raise a |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
426 \exception{ValueError}. Other possible values are \code{'ignore'} and |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
427 \code{'replace'}. |
|
15332
12aec3381c94
Marc-Andre Lemburg <mal@lemburg.com> noted that the encode() string method
Fred Drake <fdrake@acm.org>
parents:
15005
diff
changeset
|
428 \versionadded{2.0} |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
429 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
430 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
431 \begin{methoddesc}[string]{endswith}{suffix\optional{, start\optional{, end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
432 Return true if the string ends with the specified \var{suffix}, |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
433 otherwise return false. With optional \var{start}, test beginning at |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
434 that position. With optional \var{end}, stop comparing at that position. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
435 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
436 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
437 \begin{methoddesc}[string]{expandtabs}{\optional{tabsize}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
438 Return a copy of the string where all tab characters are expanded |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
439 using spaces. If \var{tabsize} is not given, a tab size of \code{8} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
440 characters is assumed. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
441 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
442 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
443 \begin{methoddesc}[string]{find}{sub\optional{, start\optional{, end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
444 Return the lowest index in the string where substring \var{sub} is |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
445 found, such that \var{sub} is contained in the range [\var{start}, |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
446 \var{end}). Optional arguments \var{start} and \var{end} are |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
447 interpreted as in slice notation. Return \code{-1} if \var{sub} is |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
448 not found. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
449 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
450 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
451 \begin{methoddesc}[string]{index}{sub\optional{, start\optional{, end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
452 Like \method{find()}, but raise \exception{ValueError} when the |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
453 substring is not found. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
454 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
455 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
456 \begin{methoddesc}[string]{isalnum}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
457 Return true if all characters in the string are alphanumeric and there |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
458 is at least one character, false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
459 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
460 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
461 \begin{methoddesc}[string]{isalpha}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
462 Return true if all characters in the string are alphabetic and there |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
463 is at least one character, false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
464 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
465 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
466 \begin{methoddesc}[string]{isdigit}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
467 Return true if there are only digit characters, false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
468 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
469 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
470 \begin{methoddesc}[string]{islower}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
471 Return true if all cased characters in the string are lowercase and |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
472 there is at least one cased character, false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
473 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
474 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
475 \begin{methoddesc}[string]{isspace}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
476 Return true if there are only whitespace characters in the string and |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
477 the string is not empty, false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
478 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
479 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
480 \begin{methoddesc}[string]{istitle}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
481 Return true if the string is a titlecased string, i.e.\ uppercase |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
482 characters may only follow uncased characters and lowercase characters |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
483 only cased ones. Return false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
484 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
485 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
486 \begin{methoddesc}[string]{isupper}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
487 Return true if all cased characters in the string are uppercase and |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
488 there is at least one cased character, false otherwise. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
489 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
490 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
491 \begin{methoddesc}[string]{join}{seq} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
492 Return a string which is the concatenation of the strings in the |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
493 sequence \var{seq}. The separator between elements is the string |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
494 providing this method. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
495 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
496 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
497 \begin{methoddesc}[string]{ljust}{width} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
498 Return the string left justified in a string of length \var{width}. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
499 Padding is done using spaces. The original string is returned if |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
500 \var{width} is less than \code{len(\var{s})}. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
501 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
502 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
503 \begin{methoddesc}[string]{lower}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
504 Return a copy of the string converted to lowercase. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
505 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
506 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
507 \begin{methoddesc}[string]{lstrip}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
508 Return a copy of the string with leading whitespace removed. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
509 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
510 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
511 \begin{methoddesc}[string]{replace}{old, new\optional{, maxsplit}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
512 Return a copy of the string with all occurrences of substring |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
513 \var{old} replaced by \var{new}. If the optional argument |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
514 \var{maxsplit} is given, only the first \var{maxsplit} occurrences are |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
515 replaced. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
516 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
517 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
518 \begin{methoddesc}[string]{rfind}{sub \optional{,start \optional{,end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
519 Return the highest index in the string where substring \var{sub} is |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
520 found, such that \var{sub} is contained within s[start,end]. Optional |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
521 arguments \var{start} and \var{end} are interpreted as in slice |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
522 notation. Return \code{-1} on failure. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
523 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
524 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
525 \begin{methoddesc}[string]{rindex}{sub\optional{, start\optional{, end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
526 Like \method{rfind()} but raises \exception{ValueError} when the |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
527 substring \var{sub} is not found. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
528 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
529 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
530 \begin{methoddesc}[string]{rjust}{width} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
531 Return the string right justified in a string of length \var{width}. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
532 Padding is done using spaces. The original string is returned if |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
533 \var{width} is less than \code{len(\var{s})}. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
534 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
535 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
536 \begin{methoddesc}[string]{rstrip}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
537 Return a copy of the string with trailing whitespace removed. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
538 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
539 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
540 \begin{methoddesc}[string]{split}{\optional{sep \optional{,maxsplit}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
541 Return a list of the words in the string, using \var{sep} as the |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
542 delimiter string. If \var{maxsplit} is given, at most \var{maxsplit} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
543 splits are done. If \var{sep} is not specified or \code{None}, any |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
544 whitespace string is a separator. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
545 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
546 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
547 \begin{methoddesc}[string]{splitlines}{\optional{keepends}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
548 Return a list of the lines in the string, breaking at line |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
549 boundaries. Line breaks are not included in the resulting list unless |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
550 \var{keepends} is given and true. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
551 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
552 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
553 \begin{methoddesc}[string]{startswith}{prefix\optional{, start\optional{, end}}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
554 Return true if string starts with the \var{prefix}, otherwise |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
555 return false. With optional \var{start}, test string beginning at |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
556 that position. With optional \var{end}, stop comparing string at that |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
557 position. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
558 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
559 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
560 \begin{methoddesc}[string]{strip}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
561 Return a copy of the string with leading and trailing whitespace |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
562 removed. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
563 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
564 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
565 \begin{methoddesc}[string]{swapcase}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
566 Return a copy of the string with uppercase characters converted to |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
567 lowercase and vice versa. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
568 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
569 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
570 \begin{methoddesc}[string]{title}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
571 Return a titlecased version of, i.e.\ words start with uppercase |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
572 characters, all remaining cased characters are lowercase. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
573 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
574 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
575 \begin{methoddesc}[string]{translate}{table\optional{, deletechars}} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
576 Return a copy of the string where all characters occurring in the |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
577 optional argument \var{deletechars} are removed, and the remaining |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
578 characters have been mapped through the given translation table, which |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
579 must be a string of length 256. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
580 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
581 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
582 \begin{methoddesc}[string]{upper}{} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
583 Return a copy of the string converted to uppercase. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
584 \end{methoddesc} |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
585 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
586 |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
587 \subsubsection{String Formatting 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
|
588 |
|
14552
a8d1c030b19f
Add some index entries to make it easier to find information on
Fred Drake <fdrake@acm.org>
parents:
14520
diff
changeset
|
589 \index{formatting, string} |
|
a8d1c030b19f
Add some index entries to make it easier to find information on
Fred Drake <fdrake@acm.org>
parents:
14520
diff
changeset
|
590 \index{string!formatting} |
|
a8d1c030b19f
Add some index entries to make it easier to find information on
Fred Drake <fdrake@acm.org>
parents:
14520
diff
changeset
|
591 \index{printf-style formatting} |
|
a8d1c030b19f
Add some index entries to make it easier to find information on
Fred Drake <fdrake@acm.org>
parents:
14520
diff
changeset
|
592 \index{sprintf-style formatting} |
|
a8d1c030b19f
Add some index entries to make it easier to find information on
Fred Drake <fdrake@acm.org>
parents:
14520
diff
changeset
|
593 |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
594 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
|
595 operator (modulo) with a string left argument interprets this string |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
596 as a C \cfunction{sprintf()} format string to be applied to the |
|
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 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
|
598 operation. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
599 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
600 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
|
601 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
|
602 argument, the right argument may also be a single non-tuple |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
603 object.\footnote{A tuple object in this case should be a singleton. |
|
15417
6b2524e9c672
Added information about the %r string formatting conversion. Added note
Fred Drake <fdrake@acm.org>
parents:
15383
diff
changeset
|
604 } The following format characters are understood: \code{\%}, |
|
6b2524e9c672
Added information about the %r string formatting conversion. Added note
Fred Drake <fdrake@acm.org>
parents:
15383
diff
changeset
|
605 \code{c}, \code{r}, \code{s}, \code{i}, \code{d}, \code{u}, \code{o}, |
|
6b2524e9c672
Added information about the %r string formatting conversion. Added note
Fred Drake <fdrake@acm.org>
parents:
15383
diff
changeset
|
606 \code{x}, \code{X}, \code{e}, \code{E}, \code{f}, \code{g}, \code{G}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
607 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
|
608 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
|
609 \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
|
610 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
|
611 ignored. The \code{\%s} conversion takes any Python object and |
|
15417
6b2524e9c672
Added information about the %r string formatting conversion. Added note
Fred Drake <fdrake@acm.org>
parents:
15383
diff
changeset
|
612 converts it to a string using \code{str()} before formatting it; the |
|
6b2524e9c672
Added information about the %r string formatting conversion. Added note
Fred Drake <fdrake@acm.org>
parents:
15383
diff
changeset
|
613 \code{\%r} conversion is similar but applies the \function{repr()} |
|
6b2524e9c672
Added information about the %r string formatting conversion. Added note
Fred Drake <fdrake@acm.org>
parents:
15383
diff
changeset
|
614 function instead. The |
|
10662
ab02334453f9
Reflow paragraph to work around LaTeX2HTML dropping a space.
Fred Drake <fdrake@acm.org>
parents:
10636
diff
changeset
|
615 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
|
616 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
|
617 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
|
618 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
619 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
|
620 \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
|
621 are replaced by \code{\%g} conversions.\footnote{ |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
622 These numbers are fairly arbitrary. They are intended to |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
623 avoid printing endless strings of meaningless digits without hampering |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
624 correct use and without having to know the exact precision of floating |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
625 point values on a particular machine. |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
626 } All other errors raise exceptions. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
627 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
634 \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
|
635 >>> 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
|
636 >>> 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
|
637 >>> 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
|
638 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
|
639 \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
|
640 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
641 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
|
642 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
|
643 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
644 Additional string operations are defined in standard module |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
645 \refmodule{string} and in built-in module \refmodule{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
|
646 \refstmodindex{string} |
| 8882 | 647 \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
|
648 |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
649 |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
650 \subsubsection{XRange Type \label{typesseq-xrange}} |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
651 |
|
15005
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
652 The xrange\obindex{xrange} type is an immutable sequence which is |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
653 commonly used for looping. The advantage of the xrange type is that an |
|
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
654 xrange object will always take the same amount of memory, no matter the |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
655 size of the range it represents. There are no consistent performance |
|
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
656 advantages. |
|
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
657 |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
658 XRange objects behave like tuples, and offer a single method: |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
659 |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
660 \begin{methoddesc}[xrange]{tolist}{} |
|
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
661 Return a list object which represents the same values as the xrange |
|
13967
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
662 object. |
|
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
663 \end{methoddesc} |
|
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
664 |
|
7b7ee58901fb
Document the range type, as suggested by Denis S. Otkidach
Fred Drake <fdrake@acm.org>
parents:
13933
diff
changeset
|
665 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
666 \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
|
667 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
668 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
|
669 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
|
670 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
|
671 (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
|
672 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
|
673 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
|
674 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
|
675 \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
|
676 \indexiii{mutable}{sequence}{types} |
|
15005
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
677 \obindex{list} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
678 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
679 \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
|
680 \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
|
681 {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
|
682 \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
|
683 {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
|
684 \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
|
685 {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
|
686 \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
|
687 {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
|
688 \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
|
689 {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
|
690 \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
|
691 {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
|
692 \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
|
693 {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
|
694 \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
|
695 {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
|
696 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
|
697 \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
|
698 {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
|
699 \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
|
700 {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
|
701 \lineiii{\var{s}.reverse()} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
702 {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
|
703 \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
|
704 {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
|
705 \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
|
706 \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
|
707 \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
|
708 \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
|
709 \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
|
710 \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
|
711 \stindex{del} |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
712 \withsubitem{(list method)}{ |
|
11183
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
713 \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
|
714 \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
|
715 \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
|
716 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
717 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
718 \begin{description} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
719 \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
|
720 multiple parameters and implicitly joined them into a tuple; this |
|
13222
5dd381aeb23b
Update version numbering from 1.6 to 2.0.
Fred Drake <fdrake@acm.org>
parents:
12223
diff
changeset
|
721 no longer works in Python 2.0. Use of this misfeature has been |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
722 deprecated since Python 1.4. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
723 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
724 \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
|
725 \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
|
726 mutable sequence types other than lists. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
727 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
728 \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
|
729 \var{s}. |
|
1e0b1967be7f
In note mentioning [].remove()'s exception, tell what exception is
Fred Drake <fdrake@acm.org>
parents:
11100
diff
changeset
|
730 |
|
13780
e20fe0052680
fixing a minor spelling mistake
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13777
diff
changeset
|
731 \item[(4)] The \method{pop()} method is only supported by the list and |
|
13777
b3903e05017f
Stop lying about [].pop() being experimental! There is no backing it out
Fred Drake <fdrake@acm.org>
parents:
13772
diff
changeset
|
732 array types. The optional argument \var{i} defaults to \code{-1}, |
|
b3903e05017f
Stop lying about [].pop() being experimental! There is no backing it out
Fred Drake <fdrake@acm.org>
parents:
13772
diff
changeset
|
733 so that by default the last item is removed and returned. |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
734 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
735 \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
|
736 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
|
737 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
|
738 of this side effect. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
739 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
740 \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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 \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
|
748 \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
|
749 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
|
750 \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
|
751 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
752 |
| 9083 | 753 \subsection{Mapping Types \label{typesmapping}} |
|
15005
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
754 \obindex{mapping} |
|
0cf5111bf09c
Use \obindex{...} instead of \indexii{...}{type} in many places; this is
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
755 \obindex{dictionary} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
756 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 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
|
765 \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
|
766 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
|
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 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
|
769 \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
|
770 \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
|
771 \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
|
772 |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
773 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
|
774 \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
|
775 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
|
776 \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
|
777 \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
|
778 \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
|
779 \bifuncindex{len} |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
780 \withsubitem{(dictionary method)}{ |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
781 \ttindex{clear()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
782 \ttindex{copy()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
783 \ttindex{has_key()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
784 \ttindex{items()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
785 \ttindex{keys()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
786 \ttindex{update()} |
|
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
787 \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
|
788 \ttindex{get()}} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
789 |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
790 \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
|
791 \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
|
792 \lineiii{\var{a}[\var{k}]}{the item of \var{a} with key \var{k}}{(1)} |
|
13764
fdbc8730d356
Two minor nits from Gerry Weiner (no working email address) about
Fred Drake <fdrake@acm.org>
parents:
13222
diff
changeset
|
793 \lineiii{\var{a}[\var{k}] = \var{v}} |
|
fdbc8730d356
Two minor nits from Gerry Weiner (no working email address) about
Fred Drake <fdrake@acm.org>
parents:
13222
diff
changeset
|
794 {set \code{\var{a}[\var{k}]} to \var{v}} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
795 {} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
796 \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
|
797 {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
|
798 {(1)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
799 \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
|
800 \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
|
801 \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
|
802 {\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
|
803 {} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
804 \lineiii{\var{a}.items()} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
805 {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
|
806 {(2)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
807 \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
|
808 \lineiii{\var{a}.update(\var{b})} |
|
13764
fdbc8730d356
Two minor nits from Gerry Weiner (no working email address) about
Fred Drake <fdrake@acm.org>
parents:
13222
diff
changeset
|
809 {\code{for k in \var{b}.keys(): \var{a}[k] = \var{b}[k]}} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
810 {(3)} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
811 \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
|
812 \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
|
813 {\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
|
814 else \var{x}} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
815 {(4)} |
|
13894
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
816 \lineiii{\var{a}.setdefault(\var{k}\optional{, \var{x}})} |
|
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
817 {\code{\var{a}[\var{k}]} if \code{\var{a}.has_key(\var{k})}, |
|
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
818 else \var{x} (also setting it)} |
|
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
819 {(5)} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
820 \end{tableiii} |
|
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
821 |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
822 \noindent |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
823 Notes: |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
824 \begin{description} |
|
10968
5ba2e4ce58cb
Some clarifications on operations for mapping types, based on comments
Fred Drake <fdrake@acm.org>
parents:
10785
diff
changeset
|
825 \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
|
826 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
|
827 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
828 \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
|
829 \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
|
830 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
|
831 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
|
832 \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
|
833 \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
|
834 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
835 \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
|
836 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
837 \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
|
838 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
|
839 provided and \var{k} is not in the map, \code{None} is returned. |
|
13894
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
840 |
|
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
841 \item[(5)] \function{setdefault()} is like \function{get()}, except |
|
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
842 that if \var{k} is missing, \var{x} is both returned and inserted into |
|
77b9e041b595
Barry's patch to document the new setdefault() method. Slightly
Guido van Rossum <guido@python.org>
parents:
13780
diff
changeset
|
843 the dictionary as the value of \var{k}. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
844 \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
|
845 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
846 |
| 9083 | 847 \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
|
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 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
|
850 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
|
851 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
852 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
853 \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
|
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 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
|
856 \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
|
857 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
|
858 can be assigned to. (Note that the \keyword{import} statement is not, |
| 9034 | 859 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
|
860 \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
|
861 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
|
862 \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
|
863 |
|
9558
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 \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
|
871 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
872 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
|
873 \code{<module 'sys' (built-in)>}. If loaded from a file, they are |
|
14557
a71385f8b4da
Use \shortversion in a number of places.
Fred Drake <fdrake@acm.org>
parents:
14552
diff
changeset
|
874 written as \code{<module 'os' from |
|
a71385f8b4da
Use \shortversion in a number of places.
Fred Drake <fdrake@acm.org>
parents:
14552
diff
changeset
|
875 '/usr/local/lib/python\shortversion/os.pyc'>}. |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
876 |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
877 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
878 \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
|
879 \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
|
880 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
881 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
|
882 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
|
883 |
|
10241
f138ba72bf2d
Update description of what modules "look like" when printed.
Fred Drake <fdrake@acm.org>
parents:
10156
diff
changeset
|
884 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
885 \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
|
886 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
887 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
|
888 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
|
889 \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
|
890 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
891 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
|
892 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
|
893 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
|
894 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
|
895 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
896 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
|
897 \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
|
898 object}\obindex{code} (see below) and \code{\var{f}.func_globals} is |
|
14520
addaba991077
When referring to namespaces, always say "namespaces" instead of
Fred Drake <fdrake@acm.org>
parents:
14485
diff
changeset
|
899 the dictionary used as the function's global namespace (this is the |
|
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 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
|
901 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
|
902 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
903 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
904 \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
|
905 \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
|
906 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
907 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
|
908 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
|
909 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
|
910 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
|
911 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
912 The implementation adds two special read-only attributes to class |
| 9034 | 913 instance methods: \code{\var{m}.im_self} is the object on which the |
| 914 method operates, and \code{\var{m}.im_func} is the function | |
| 915 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
|
916 \var{arg-2}, \textrm{\ldots}, \var{arg-n})} is completely equivalent to |
| 9034 | 917 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
|
918 \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
|
919 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
920 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
|
921 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
|
922 |
| 9083 | 923 |
| 924 \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
|
925 \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
|
926 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
927 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
|
928 ``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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 attribute. |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
934 \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
|
935 \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
|
936 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
937 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
|
938 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
|
939 \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
|
940 \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
|
941 \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
|
942 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
943 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
|
944 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
|
945 |
| 9083 | 946 |
| 947 \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
|
948 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 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
|
953 \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
|
954 \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
|
955 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
956 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
|
957 |
| 9083 | 958 |
| 959 \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
|
960 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
961 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
|
962 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
|
963 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
|
964 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
965 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
|
966 |
| 9083 | 967 |
| 968 \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
|
969 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
970 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
|
971 \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
|
972 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
|
973 \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
|
974 |
|
ddaac06ec326
Document Ellipsis (not much of a documentation snippet, but at least
Guido van Rossum <guido@python.org>
parents:
8730
diff
changeset
|
975 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
|
976 |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
977 |
|
10636
9fd29021d147
Added index entry for "file objects"; this is appearantly referenced
Fred Drake <fdrake@acm.org>
parents:
10606
diff
changeset
|
978 \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
|
979 \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
|
980 |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
981 File objects are implemented using C's \code{stdio} package and can be |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
982 created with the built-in function |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
983 \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
|
984 \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
|
985 by some other built-in functions and methods, e.g., |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
986 \function{os.popen()} and \function{os.fdopen()} and the |
|
9461
9ffd604807c2
Don't describe something as "below"; that won't make sense for the
Fred Drake <fdrake@acm.org>
parents:
9318
diff
changeset
|
987 \method{makefile()} method of socket objects. |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
988 \refstmodindex{os} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
989 \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
|
990 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
991 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
|
992 \exception{IOError} is raised. This includes situations where the |
|
fa867d8ee7eb
Remove some remaining {\rm ...} constructs.
Fred Drake <fdrake@acm.org>
parents:
9523
diff
changeset
|
993 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
|
994 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
|
995 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
996 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
|
997 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
998 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
999 \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
|
1000 Close the file. A closed file cannot be read or written anymore. |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1001 Any operation which requires that the file be open will raise a |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1002 \exception{ValueError} after the file has been closed. Calling |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1003 \method{close()} more than once is allowed. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1004 \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
|
1005 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1006 \begin{methoddesc}[file]{flush}{} |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1007 Flush the internal buffer, like \code{stdio}'s |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1008 \cfunction{fflush()}. This may be a no-op on some file-like |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1009 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
|
1010 \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
|
1011 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1012 \begin{methoddesc}[file]{isatty}{} |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1013 Return true if the file is connected to a tty(-like) device, else |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1014 false. \strong{Note:} If a file-like object is not associated |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1015 with a real file, this method should \emph{not} be implemented. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1016 \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
|
1017 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1018 \begin{methoddesc}[file]{fileno}{} |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1019 \index{file descriptor} |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1020 \index{descriptor, file} |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1021 Return the integer ``file descriptor'' that is used by the |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1022 underlying implementation to request I/O operations from the |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1023 operating system. This can be useful for other, lower level |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1024 interfaces that use file descriptors, e.g.\ module |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1025 \refmodule{fcntl}\refbimodindex{fcntl} or \function{os.read()} and |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1026 friends. \strong{Note:} File-like objects which do not have a real |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1027 file descriptor should \emph{not} provide this method! |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1028 \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
|
1029 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1030 \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
|
1031 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
|
1032 \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
|
1033 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
|
1034 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
|
1035 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
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 \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
|
1041 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1042 \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
|
1043 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
|
1044 kept in the string\footnote{ |
|
7ee1e3134147
Fixed latex2html weirdness with footnotes.
Fred Drake <fdrake@acm.org>
parents:
10241
diff
changeset
|
1045 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
|
1046 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
|
1047 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
|
1048 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
|
1049 you can tell whether the last line of a file ended in a newline |
|
13933
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
1050 or not (yes this happens!). |
|
4d14eef8ea07
Added Marc-Andre Lemburg's documentation for string methods, with some
Fred Drake <fdrake@acm.org>
parents:
13894
diff
changeset
|
1051 } (but may be absent when a file ends with an |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1052 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
|
1053 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
|
1054 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
|
1055 An empty string is returned when \EOF{} is hit |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1056 immediately. Note: Unlike \code{stdio}'s \cfunction{fgets()}, the |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1057 returned string contains null characters (\code{'\e 0'}) if they |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1058 occurred in the input. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1059 \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
|
1060 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1061 \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
|
1062 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
|
1063 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
|
1064 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
|
1065 approximately \var{sizehint} bytes (possibly after rounding up to an |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1066 internal buffer size) are read. Objects implementing a file-like |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1067 interface may choose to ignore \var{sizehint} if it cannot be |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1068 implemented, or cannot be implemented efficiently. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1069 \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
|
1070 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1071 \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
|
1072 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
|
1073 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
|
1074 (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
|
1075 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
|
1076 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
|
1077 \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
|
1078 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1079 \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
|
1080 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
|
1081 \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
|
1082 \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
|
1083 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1084 \begin{methoddesc}[file]{truncate}{\optional{size}} |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1085 Truncate the file's size. If the optional \var{size} argument |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1086 present, the file is truncated to (at most) that size. The size |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1087 defaults to the current position. Availability of this function |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1088 depends on the operating system version (for example, not all |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1089 \UNIX{} versions support this operation). |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1090 \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
|
1091 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1092 \begin{methoddesc}[file]{write}{str} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
11463
diff
changeset
|
1093 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
|
1094 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
|
1095 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
|
1096 \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
|
1097 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1098 \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
|
1099 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
|
1100 (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
|
1101 \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
|
1102 \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
|
1103 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1104 |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1105 File objects also offer a number of other interesting attributes. |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1106 These are not required for file-like objects, but should be |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1107 implemented if they make sense for the particular 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
|
1108 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1109 \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
|
1110 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
|
1111 read-only attribute; the \method{close()} method changes the value. |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1112 It may not be available on all file-like 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
|
1113 \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
|
1114 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1115 \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
|
1116 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
|
1117 \function{open()} built-in function, this will be the value of the |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1118 \var{mode} parameter. This is a read-only attribute and may not be |
|
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1119 present on all file-like 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
|
1120 \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
|
1121 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1122 \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
|
1123 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
|
1124 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
|
1125 file object, of the form \samp{<\mbox{\ldots}>}. This is a read-only |
|
14685
faf3e734254d
Clarify a number of issues about the file-like object API based on
Fred Drake <fdrake@acm.org>
parents:
14557
diff
changeset
|
1126 attribute and may not be present on all file-like 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
|
1127 \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
|
1128 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1129 \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
|
1130 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
|
1131 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
|
1132 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
|
1133 writable \member{softspace} attribute, which should be initialized to |
|
14485
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
1134 zero. This will be automatic for most classes implemented in Python |
|
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
1135 (care may be needed for objects that override attribute access); types |
|
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
1136 implemented in C will have to provide a writable |
|
ac0246586d52
Improve a couple of references to the language reference, making them
Fred Drake <fdrake@acm.org>
parents:
14044
diff
changeset
|
1137 \member{softspace} attribute. |
|
14705
4712f5b8f279
Clarify that the softspace attribute is used by print for state management,
Fred Drake <fdrake@acm.org>
parents:
14685
diff
changeset
|
1138 \strong{Note:} This attribute is not used to control the |
|
4712f5b8f279
Clarify that the softspace attribute is used by print for state management,
Fred Drake <fdrake@acm.org>
parents:
14685
diff
changeset
|
1139 \keyword{print} statement, but to allow the implementation of |
|
4712f5b8f279
Clarify that the softspace attribute is used by print for state management,
Fred Drake <fdrake@acm.org>
parents:
14685
diff
changeset
|
1140 \keyword{print} to keep track of its internal state. |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1141 \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
|
1142 |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1143 |
|
10156
0f7d694bc334
Make sure all HTML pages generated from this section have reasonable
Fred Drake <fdrake@acm.org>
parents:
10147
diff
changeset
|
1144 \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
|
1145 |
|
11463
17e12305973e
Use \citetitle and \programopt as appropriate.
Fred Drake <fdrake@acm.org>
parents:
11183
diff
changeset
|
1146 See the \citetitle[../ref/ref.html]{Python Reference Manual} for this |
|
14044
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
1147 information. It describes stack frame objects, traceback objects, and |
|
a905c5aa0691
As pointed out by Denis S. Otkidach <den@analyt.chem.msu.ru>, xrange()
Fred Drake <fdrake@acm.org>
parents:
13967
diff
changeset
|
1148 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
|
1149 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1150 |
| 9083 | 1151 \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
|
1152 |
|
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1153 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
|
1154 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
|
1155 |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1156 \begin{memberdesc}[object]{__dict__} |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1157 A dictionary or other mapping object used to store an |
| 9083 | 1158 object's (writable) attributes. |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1159 \end{memberdesc} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1160 |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1161 \begin{memberdesc}[object]{__methods__} |
| 9083 | 1162 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
|
1163 e.g., \code{[].__methods__} yields |
| 9083 | 1164 \code{['append', 'count', 'index', 'insert', 'pop', 'remove', |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1165 'reverse', 'sort']}. This usually does not need to be explicitly |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1166 provided by the object. |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1167 \end{memberdesc} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1168 |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1169 \begin{memberdesc}[object]{__members__} |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1170 Similar to \member{__methods__}, but lists data attributes. This |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1171 usually does not need to be explicitly provided by the object. |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1172 \end{memberdesc} |
|
8730
8a306dfd9f33
Move files around to get the names to match the module names except for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1173 |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1174 \begin{memberdesc}[instance]{__class__} |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1175 The class to which a class instance belongs. |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1176 \end{memberdesc} |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1177 |
|
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1178 \begin{memberdesc}[class]{__bases__} |
| 9083 | 1179 The tuple of base classes of a class object. |
|
15383
eeb7c8a5b79f
Document the proper exception to be raised by I/O operations on closed
Fred Drake <fdrake@acm.org>
parents:
15332
diff
changeset
|
1180 \end{memberdesc} |
