8:
Notes:
The
'u'type code corresponds to Python’s obsolete unicode character (
Py_UNIC:
- class
array.
array(typecode[, initializer])¶
A new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a list, a bytes-like object, or iterable over elements of the appropriate type.
If given a list or string, the initializer is passed to the new array’s
fromlist(),
frombytes(), bytes-like Protocol..
array.
frombytes(s)¶
Appends items from the string, interpreting the string as an array of machine values (as if it had been read from a file using the
fromfile()method).
New in version 3.2:
fromstring()is renamed to
frombytes()for clarity.()¶
Deprecated alias for
frombytes().
array.
fromunicode(s)¶
Extends this array with data from the given unicode string. The array must be a type
'u'array; otherwise a
ValueErroris raised. Use
array.frombytes.
tobytes()¶
Convert the array to an array of machine values and return the bytes representation (the same sequence of bytes that would be written to a file by the
tofile()method.)
New inis raised. Use
array.tobytes()
'u', otherwise it is a
list of numbers. The string is guaranteed to be able to be converted back to an
array with the same type and value using
eval(), so long as the
array class has been imported using
from array import array.
Examples:
array('l') array('u', 'hello \u2641') array('l', [1, 2, 3, 4, 5]) array('d', [1.0, 2.0, 3.14])
See also
-.