summaryrefslogtreecommitdiffstats
path: root/Doc/library/functions.rst
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
commit98297ee7815939b124156e438b22bd652d67b5db (patch)
treea9d239ebd87c73af2571ab48003984c4e18e27e5 /Doc/library/functions.rst
parenta19f80c6df2df5e8a5d0cff37131097835ef971e (diff)
downloadcpython-98297ee7815939b124156e438b22bd652d67b5db.zip
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.gz
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.bz2
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.
Diffstat (limited to 'Doc/library/functions.rst')
-rw-r--r--Doc/library/functions.rst27
1 files changed, 20 insertions, 7 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 63f2c33..d554a08 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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