annotate Doc/lib/libarray.tex @ 7804:6d04e8c817fb legacy-trunk

Use {seealso} environment to refer to the struct module. Document ArrayType. Use {memberdesc} and {methoddesc} environments, as appropriate. Minor nits.
author Fred Drake <fdrake@acm.org>
date Fri, 03 Apr 1998 03:35:24 +0000
parents 0cbc9df882b6
children 8e5223680a9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2576
f47bc5554418 mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents: 2491
diff changeset
1 \section{Built-in Module \sectcode{array}}
5818
3468ea8645ca AMK's megapatch:
Guido van Rossum <guido@python.org>
parents: 4877
diff changeset
2 \label{module-array}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 \bimodindex{array}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 \index{arrays}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 This module defines a new object type which can efficiently represent
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 an array of basic values: characters, integers, floating point
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 numbers. Arrays are sequence types and behave very much like lists,
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 except that the type of objects stored in them is constrained. The
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 type is specified at object creation time by using a \dfn{type code},
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 which is a single character. The following type codes are defined:
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
13 \begin{tableiii}{|c|c|c|}{character}{Type code}{Type}{Minimum size in bytes}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 \lineiii{'c'}{character}{1}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 \lineiii{'b'}{signed integer}{1}
4877
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
16 \lineiii{'B'}{unsigned integer}{1}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 \lineiii{'h'}{signed integer}{2}
4877
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
18 \lineiii{'H'}{unsigned integer}{2}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 \lineiii{'i'}{signed integer}{2}
4877
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
20 \lineiii{'I'}{unsigned integer}{2}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 \lineiii{'l'}{signed integer}{4}
4877
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
22 \lineiii{'L'}{unsigned integer}{4}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 \lineiii{'f'}{floating point}{4}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 \lineiii{'d'}{floating point}{8}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 \end{tableiii}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 The actual representation of values is determined by the machine
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
28 architecture (strictly speaking, by the \C{} implementation). The actual
4877
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
29 size can be accessed through the \var{itemsize} attribute. The values
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
30 stored for \code{'L'} and \code{'I'} items will be represented as
e57a8de5aeb3 Added unsigned data formats (B, H, I, L).
Guido van Rossum <guido@python.org>
parents: 2609
diff changeset
31 Python long integers when retrieved, because Python's plain integer
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
32 type cannot represent the full range of \C{}'s unsigned (long) integers.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
2609
7ef72873e4d6 restructured library manual accordiung to functional group
Guido van Rossum <guido@python.org>
parents: 2576
diff changeset
34
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
35 The module defines the following function and type object:
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7505
diff changeset
37 \begin{funcdesc}{array}{typecode\optional{, initializer}}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 Return a new array whose items are restricted by \var{typecode}, and
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 initialized from the optional \var{initializer} value, which must be a
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 list or a string. The list or string is passed to the new array's
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
41 \method{fromlist()} or \method{fromstring()} method (see below) to add
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 initial items to the array.
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
45 \begin{datadesc}{ArrayType}
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
46 Type object corresponding to the objects returned by
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
47 \function{array()}.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
50
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
51 Array objects support the following data items and methods:
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
53 \begin{memberdesc}[array]{typecode}
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
54 The typecode character used to create the array.
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
55 \end{memberdesc}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
56
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
57 \begin{memberdesc}[array]{itemsize}
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
58 The length in bytes of one array item in the internal representation.
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
59 \end{memberdesc}
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
60
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
61
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
62 \begin{methoddesc}[array]{append}{x}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 Append a new item with value \var{x} to the end of the array.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
64 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
66 \begin{methoddesc}[array]{buffer_info}{}
6965
dce838cd42c1 Added missing "\" to "\var{address}, var{length}" in buffer_info() description.
Fred Drake <fdrake@acm.org>
parents: 6875
diff changeset
67 Return a tuple \code{(\var{address}, \var{length})} giving the current
6022
802470c7a50f Added buffer_info() docs.
Guido van Rossum <guido@python.org>
parents: 5818
diff changeset
68 memory address and the length in bytes of the buffer used to hold
802470c7a50f Added buffer_info() docs.
Guido van Rossum <guido@python.org>
parents: 5818
diff changeset
69 array's contents. This is occasionally useful when working with
802470c7a50f Added buffer_info() docs.
Guido van Rossum <guido@python.org>
parents: 5818
diff changeset
70 low-level (and inherently unsafe) I/O interfaces that require memory
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
71 addresses, such as certain \cfunction{ioctl()} operations. The returned
6022
802470c7a50f Added buffer_info() docs.
Guido van Rossum <guido@python.org>
parents: 5818
diff changeset
72 numbers are valid as long as the array exists and no length-changing
802470c7a50f Added buffer_info() docs.
Guido van Rossum <guido@python.org>
parents: 5818
diff changeset
73 operations are applied to it.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
74 \end{methoddesc}
6022
802470c7a50f Added buffer_info() docs.
Guido van Rossum <guido@python.org>
parents: 5818
diff changeset
75
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
76 \begin{methoddesc}[array]{byteswap}{x}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 ``Byteswap'' all items of the array. This is only supported for
1767
907605320a5f Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents: 1471
diff changeset
78 integer values. It is useful when reading data from a file written
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 on a machine with a different byte order.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
80 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
82 \begin{methoddesc}[array]{fromfile}{f, n}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 Read \var{n} items (as machine values) from the file object \var{f}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 and append them to the end of the array. If less than \var{n} items
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
85 are available, \exception{EOFError} is raised, but the items that were
2576
f47bc5554418 mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents: 2491
diff changeset
86 available are still inserted into the array. \var{f} must be a real
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
87 built-in file object; something else with a \method{read()} method won't
2576
f47bc5554418 mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents: 2491
diff changeset
88 do.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
89 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
91 \begin{methoddesc}[array]{fromlist}{list}
2491
fb8e08ec88dd changes (suggested) by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
92 Append items from the list. This is equivalent to
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
93 \samp{for x in \var{list}:\ a.append(x)}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 except that if there is a type error, the array is unchanged.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
95 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
96
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
97 \begin{methoddesc}[array]{fromstring}{s}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 Appends items from the string, interpreting the string as an
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 array of machine values (i.e. as if it had been read from a
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
100 file using the \method{fromfile()} method).
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
101 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
103 \begin{methoddesc}[array]{insert}{i, x}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 Insert a new item with value \var{x} in the array before position
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 \var{i}.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
106 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
108 \begin{methoddesc}[array]{read}{f, n}
7505
ef980e17b593 Deprecate the read() and write() methods.
Fred Drake <fdrake@acm.org>
parents: 7501
diff changeset
109 \deprecated {1.5.1}
ef980e17b593 Deprecate the read() and write() methods.
Fred Drake <fdrake@acm.org>
parents: 7501
diff changeset
110 {Use the \method{fromfile()} method.}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
111 Read \var{n} items (as machine values) from the file object \var{f}
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
112 and append them to the end of the array. If less than \var{n} items
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
113 are available, \exception{EOFError} is raised, but the items that were
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
114 available are still inserted into the array. \var{f} must be a real
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
115 built-in file object; something else with a \method{read()} method won't
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
116 do.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
117 \end{methoddesc}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
118
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
119 \begin{methoddesc}[array]{reverse}{}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
120 Reverse the order of the items in the array.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
121 \end{methoddesc}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
122
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
123 \begin{methoddesc}[array]{tofile}{f}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 Write all items (as machine values) to the file object \var{f}.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
125 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
127 \begin{methoddesc}[array]{tolist}{}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 Convert the array to an ordinary list with the same items.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
129 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
131 \begin{methoddesc}[array]{tostring}{}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 Convert the array to an array of machine values and return the
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 string representation (the same sequence of bytes that would
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
134 be written to a file by the \method{tofile()} method.)
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
135 \end{methoddesc}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
136
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
137 \begin{methoddesc}[array]{write}{f}
7505
ef980e17b593 Deprecate the read() and write() methods.
Fred Drake <fdrake@acm.org>
parents: 7501
diff changeset
138 \deprecated {1.5.1}
ef980e17b593 Deprecate the read() and write() methods.
Fred Drake <fdrake@acm.org>
parents: 7501
diff changeset
139 {Use the \method{tofile()} method.}
7501
d17db3ebfbc2 Updates by AMK.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
140 Write all items (as machine values) to the file object \var{f}.
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
141 \end{methoddesc}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 When an array object is printed or converted to a string, it is
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 represented as \code{array(\var{typecode}, \var{initializer})}. The
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 \var{initializer} is omitted if the array is empty, otherwise it is a
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 string if the \var{typecode} is \code{'c'}, otherwise it is a list of
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 numbers. The string is guaranteed to be able to be converted back to
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 an array with the same type and value using reverse quotes
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 (\code{``}). Examples:
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
7277
bf4e790bd61a Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents: 6965
diff changeset
151 \begin{verbatim}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 array('l')
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 array('c', 'hello world')
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 array('l', [1, 2, 3, 4, 5])
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 array('d', [1.0, 2.0, 3.14])
7277
bf4e790bd61a Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents: 6965
diff changeset
156 \end{verbatim}
7804
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
157
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
158
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
159 \begin{seealso}
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
160 \seemodule{struct}{Packing and unpacking of heterogeneous binary data.}
6d04e8c817fb Use {seealso} environment to refer to the struct module.
Fred Drake <fdrake@acm.org>
parents: 7712
diff changeset
161 \end{seealso}