array file
array file
**********************************************
======================================================================
+-------------+----------------------+---------------------
+-------------------------+---------+
| Type code | C Type | Python Type | Minimum size in bytes
| Notes |
|=============|======================|=====================|
=========================|=========|
| "'b'" | signed char | int | 1
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'B'" | unsigned char | int | 1
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'u'" | Py_UNICODE | Unicode character | 2
| (1) |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'h'" | signed short | int | 2
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'H'" | unsigned short | int | 2
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'i'" | signed int | int | 2
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'I'" | unsigned int | int | 2
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'l'" | signed long | int | 4
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'L'" | unsigned long | int | 4
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'q'" | signed long long | int | 8
| (2) |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'Q'" | unsigned long long | int | 8
| (2) |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'f'" | float | float | 4
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
| "'d'" | double | float | 8
| |
+-------------+----------------------+---------------------
+-------------------------+---------+
Notes:
2. The "'q'" and "'Q'" type codes are available only if the
platform C compiler used to build Python supports C "long long",
or, on Windows, "__int64".
array.typecodes
array.typecode
array.itemsize
array.append(x)
Append a new item with value *x* to the end of the array.
array.buffer_info()
Note: When using array objects from code written in C or C++ (the
only way to effectively make use of this information), it makes
more sense to use the buffer interface supported by array
objects. This method is maintained for backward compatibility and
should be avoided in new code. The buffer interface is
documented in Buffer Protocol.
array.byteswap()
array.count(x)
array.extend(iterable)
array.frombytes(s)
array.fromfile(f, n)
Read *n* items (as machine values) from the *file object* *f* and
append them to the end of the array. If less than *n* items are
available, "EOFError" is raised, but the items that were available
are still inserted into the array. *f* must be a real built-in file
object; something else with a "read()" method won't do.
array.fromlist(list)
array.fromstring()
array.fromunicode(s)
Extends this array with data from the given unicode string. The
array must be a type "'u'" array; otherwise a "ValueError" is
raised. Use "array.frombytes(unicodestring.encode(enc))" to append
Unicode data to an array of some other type.
array.index(x)
Return the smallest *i* such that *i* is the index of the first
occurrence of *x* in the array.
array.insert(i, x)
Insert a new item with value *x* in the array before position *i*.
Negative values are treated as being relative to the end of the
array.
array.pop([i])
Removes the item with the index *i* from the array and returns it.
The optional argument defaults to "-1", so that by default the last
item is removed and returned.
array.remove(x)
array.reverse()
array.tobytes()
array.tofile(f)
Write all items (as machine values) to the *file object* *f*.
array.tolist()
array.tostring()
array.tounicode()
array('l')
array('u', 'hello \u2641')
array('l', [1, 2, 3, 4, 5])
array('d', [1.0, 2.0, 3.14])
See also:
Module "struct"
Packing and unpacking of heterogeneous binary data.
Module "xdrlib"
Packing and unpacking of External Data Representation (XDR) data
as used in some remote procedure call systems.