mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Issue #8990: array.fromstring() and array.tostring() get renamed to
frombytes() and tobytes(), respectively, to avoid confusion. Furthermore, array.frombytes(), array.extend() as well as the array.array() constructor now accept bytearray objects. Patch by Thomas Jollans.
This commit is contained in:
parent
42cb462682
commit
1ce3eb5c5b
12 changed files with 167 additions and 48 deletions
|
|
@ -60,7 +60,7 @@ The module defines the following type:
|
|||
appropriate type.
|
||||
|
||||
If given a list or string, the initializer is passed to the new array's
|
||||
:meth:`fromlist`, :meth:`fromstring`, or :meth:`fromunicode` method (see below)
|
||||
:meth:`fromlist`, :meth:`frombytes`, or :meth:`fromunicode` method (see below)
|
||||
to add initial items to the array. Otherwise, the iterable initializer is
|
||||
passed to the :meth:`extend` method.
|
||||
|
||||
|
|
@ -136,6 +136,15 @@ The following data items and methods are also supported:
|
|||
must be the right type to be appended to the array.
|
||||
|
||||
|
||||
.. method:: 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 :meth:`fromfile` method).
|
||||
|
||||
.. versionadded:: 3.2
|
||||
:meth:`fromstring` is renamed to :meth:`frombytes` for clarity.
|
||||
|
||||
|
||||
.. method:: array.fromfile(f, n)
|
||||
|
||||
Read *n* items (as machine values) from the file object *f* and append them to
|
||||
|
|
@ -151,17 +160,16 @@ The following data items and methods are also supported:
|
|||
a.append(x)`` except that if there is a type error, the array is unchanged.
|
||||
|
||||
|
||||
.. method:: array.fromstring(s)
|
||||
.. method:: array.fromstring()
|
||||
|
||||
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 :meth:`fromfile` method).
|
||||
Deprecated alias for :meth:`frombytes`.
|
||||
|
||||
|
||||
.. method:: array.fromunicode(s)
|
||||
|
||||
Extends this array with data from the given unicode string. The array must
|
||||
be a type ``'u'`` array; otherwise a :exc:`ValueError` is raised. Use
|
||||
``array.fromstring(unicodestring.encode(enc))`` to append Unicode data to an
|
||||
``array.frombytes(unicodestring.encode(enc))`` to append Unicode data to an
|
||||
array of some other type.
|
||||
|
||||
|
||||
|
|
@ -194,6 +202,16 @@ The following data items and methods are also supported:
|
|||
Reverse the order of the items in the array.
|
||||
|
||||
|
||||
.. method:: array.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 :meth:`tofile` method.)
|
||||
|
||||
.. versionadded:: 3.2
|
||||
:meth:`tostring` is renamed to :meth:`tobytes` for clarity.
|
||||
|
||||
|
||||
.. method:: array.tofile(f)
|
||||
|
||||
Write all items (as machine values) to the file object *f*.
|
||||
|
|
@ -206,15 +224,13 @@ The following data items and methods are also supported:
|
|||
|
||||
.. method:: array.tostring()
|
||||
|
||||
Convert the array to an array of machine values and return the string
|
||||
representation (the same sequence of bytes that would be written to a file by
|
||||
the :meth:`tofile` method.)
|
||||
Deprecated alias for :meth:`tobytes`.
|
||||
|
||||
|
||||
.. method:: array.tounicode()
|
||||
|
||||
Convert the array to a unicode string. The array must be a type ``'u'`` array;
|
||||
otherwise a :exc:`ValueError` is raised. Use ``array.tostring().decode(enc)`` to
|
||||
otherwise a :exc:`ValueError` is raised. Use ``array.tobytes().decode(enc)`` to
|
||||
obtain a unicode string from an array of some other type.
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue