mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
This commit is contained in:
parent
a19f80c6df
commit
98297ee781
148 changed files with 2533 additions and 3517 deletions
|
@ -118,18 +118,19 @@ available. They are listed here in alphabetical order.
|
|||
.. index:: pair: Boolean; type
|
||||
|
||||
|
||||
.. function:: bytes([arg[, encoding[, errors]]])
|
||||
.. function:: buffer([arg[, encoding[, errors]]])
|
||||
|
||||
Return a new array of bytes. The :class:`bytes` type is a mutable sequence
|
||||
Return a new array of bytes. The :class:`buffer` type is an immutable sequence
|
||||
of integers in the range 0 <= x < 256. It has most of the usual methods of
|
||||
mutable sequences, described in :ref:`typesseq-mutable`, as well as a few
|
||||
methods borrowed from strings, described in :ref:`bytes-methods`.
|
||||
mutable sequences, described in :ref:`typesseq-mutable`, as well as most methods
|
||||
that the :class:`str` type has, see :ref:`bytes-methods`.
|
||||
|
||||
The optional *arg* parameter can be used to initialize the array in a few
|
||||
different ways:
|
||||
|
||||
* If it is a *string*, you must also give the *encoding* (and optionally,
|
||||
*errors*) parameters; :func:`bytes` then acts like :meth:`str.encode`.
|
||||
*errors*) parameters; :func:`buffer` then converts the Unicode string to
|
||||
bytes using :meth:`str.encode`.
|
||||
|
||||
* If it is an *integer*, the array will have that size and will be
|
||||
initialized with null bytes.
|
||||
|
@ -137,12 +138,24 @@ available. They are listed here in alphabetical order.
|
|||
* If it is an object conforming to the *buffer* interface, a read-only buffer
|
||||
of the object will be used to initialize the bytes array.
|
||||
|
||||
* If it is an *iterable*, it must be an iterable of integers in the range 0
|
||||
<= x < 256, which are used as the initial contents of the array.
|
||||
* If it is an *iterable*, it must be an iterable of integers in the range
|
||||
``0 <= x < 256``, which are used as the initial contents of the array.
|
||||
|
||||
Without an argument, an array of size 0 is created.
|
||||
|
||||
|
||||
.. function:: bytes([arg[, encoding[, errors]]])
|
||||
|
||||
Return a new "bytes" object, which is an immutable sequence of integers in
|
||||
the range ``0 <= x < 256``. :class:`bytes` is an immutable version of
|
||||
:class:`buffer` -- it has the same non-mutating methods and the same indexing
|
||||
and slicing behavior.
|
||||
|
||||
Accordingly, constructor arguments are interpreted as for :func:`buffer`.
|
||||
|
||||
Bytes objects can also be created with literals, see :ref:`strings`.
|
||||
|
||||
|
||||
.. function:: chr(i)
|
||||
|
||||
Return the string of one character whose Unicode codepoint is the integer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue