rest25/library/array.rst => rest262/library/array.rst
f1
2:mod:`array` --- Efficient arrays of numeric values
3===================================================
4
5.. module:: array
n6-   :synopsis: Efficient arrays of uniformly typed numeric values.
n6+   :synopsis: Space efficient arrays of uniformly typed numeric values.
7
8
9.. index:: single: arrays
10
n11-This module defines an object type which can efficiently represent an array of
n11+This module defines an object type which can compactly represent an array of
12basic values: characters, integers, floating point numbers.  Arrays are sequence
13types and behave very much like lists, except that the type of objects stored in
14them is constrained.  The type is specified at object creation time by using a
15:dfn:`type code`, which is a single character.  The following type codes are
16defined:
17
18+-----------+----------------+-------------------+-----------------------+
19| Type code | C Type         | Python Type       | Minimum size in bytes |
107   exists and no length-changing operations are applied to it.
108
109   .. note::
110
111      When using array objects from code written in C or C++ (the only way to
112      effectively make use of this information), it makes more sense to use the buffer
113      interface supported by array objects.  This method is maintained for backward
114      compatibility and should be avoided in new code.  The buffer interface is
n115-      documented in the Python/C API Reference Manual (XXX reference:
n115+      documented in :ref:`bufferobjects`.
116-      ../api/newTypes.html).
117
118
119.. method:: array.byteswap()
120
121   "Byteswap" all items of the array.  This is only supported for values which are
122   1, 2, 4, or 8 bytes in size; for other types of values, :exc:`RuntimeError` is
123   raised.  It is useful when reading data from a file written on a machine with a
124   different byte order.
158.. method:: array.fromstring(s)
159
160   Appends items from the string, interpreting the string as an array of machine
161   values (as if it had been read from a file using the :meth:`fromfile` method).
162
163
164.. method:: array.fromunicode(s)
165
n166-   Extends this array with data from the given unicode string.  The array must be a
n165+   Extends this array with data from the given unicode string.  The array must
167-   type ``'u'`` array; otherwise a :exc:`ValueError` is raised.  Use
166+   be a type ``'u'`` array; otherwise a :exc:`ValueError` is raised.  Use
168-   ``array.fromstring(ustr.decode(enc))`` to append Unicode data to an array of
167+   ``array.fromstring(unicodestring.encode(enc))`` to append Unicode data to an
169-   some other type.
168+   array of some other type.
170
171
172.. method:: array.index(x)
173
174   Return the smallest *i* such that *i* is the index of the first occurrence of
175   *x* in the array.
176
177
240      Use the :meth:`tofile` method.
241
242   Write all items (as machine values) to the file object *f*.
243
244When an array object is printed or converted to a string, it is represented as
245``array(typecode, initializer)``.  The *initializer* is omitted if the array is
246empty, otherwise it is a string if the *typecode* is ``'c'``, otherwise it is a
247list of numbers.  The string is guaranteed to be able to be converted back to an
n248-array with the same type and value using reverse quotes (``````), so long as the
n247+array with the same type and value using :func:`eval`, so long as the
249:func:`array` function has been imported using ``from array import array``.
250Examples::
251
252   array('l')
253   array('c', 'hello world')
n254-   array('u', u'hello \textbackslash u2641')
n253+   array('u', u'hello \u2641')
255   array('l', [1, 2, 3, 4, 5])
256   array('d', [1.0, 2.0, 3.14])
257
258
259.. seealso::
260
261   Module :mod:`struct`
262      Packing and unpacking of heterogeneous binary data.
263
264   Module :mod:`xdrlib`
265      Packing and unpacking of External Data Representation (XDR) data as used in some
266      remote procedure call systems.
267
268   `The Numerical Python Manual <http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm>`_
269      The Numeric Python extension (NumPy) defines another array type; see
t270-      `<http://numpy.sourceforge.net/>`_ for further information about Numerical
t269+      http://numpy.sourceforge.net/ for further information about Numerical Python.
271-      Python.  (A PDF version of the NumPy manual is available at
270+      (A PDF version of the NumPy manual is available at
272-      `<http://numpy.sourceforge.net/numdoc/numdoc.pdf>`_).
271+      http://numpy.sourceforge.net/numdoc/numdoc.pdf).
273
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op