Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9541463a
Commit
9541463a
authored
Nov 22, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update docs for buffer -> bytearray rename.
parent
faddf1fb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
35 deletions
+34
-35
Doc/library/functions.rst
Doc/library/functions.rst
+8
-8
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+26
-27
No files found.
Doc/library/functions.rst
View file @
9541463a
...
@@ -118,18 +118,18 @@ available. They are listed here in alphabetical order.
...
@@ -118,18 +118,18 @@ available. They are listed here in alphabetical order.
..
index
::
pair
:
Boolean
;
type
..
index
::
pair
:
Boolean
;
type
..
function
::
b
uffer
([
arg
[,
encoding
[,
errors
]]])
..
function
::
b
ytearray
([
arg
[,
encoding
[,
errors
]]])
Return
a
new
array
of
bytes
.
The
:
class
:`
b
uffer
`
type
is
an
immutable
sequenc
e
Return
a
new
array
of
bytes
.
The
:
class
:`
b
ytearray
`
type
is
an
immutabl
e
of
integers
in
the
range
0
<=
x
<
256.
It
has
most
of
the
usual
methods
of
sequence
of
integers
in
the
range
0
<=
x
<
256.
It
has
most
of
the
usual
m
utable
sequences
,
described
in
:
ref
:`
typesseq
-
mutable
`,
as
well
as
most
methods
m
ethods
of
mutable
sequences
,
described
in
:
ref
:`
typesseq
-
mutable
`,
as
well
that
the
:
class
:`
str
`
type
has
,
see
:
ref
:`
bytes
-
methods
`.
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
The
optional
*
arg
*
parameter
can
be
used
to
initialize
the
array
in
a
few
different
ways
:
different
ways
:
*
If
it
is
a
*
string
*,
you
must
also
give
the
*
encoding
*
(
and
optionally
,
*
If
it
is
a
*
string
*,
you
must
also
give
the
*
encoding
*
(
and
optionally
,
*
errors
*)
parameters
;
:
func
:`
b
uffer
`
then
converts
the
Unicode
string
to
*
errors
*)
parameters
;
:
func
:`
b
ytearray
`
then
converts
the
Unicode
string
to
bytes
using
:
meth
:`
str
.
encode
`.
bytes
using
:
meth
:`
str
.
encode
`.
*
If
it
is
an
*
integer
*,
the
array
will
have
that
size
and
will
be
*
If
it
is
an
*
integer
*,
the
array
will
have
that
size
and
will
be
...
@@ -148,8 +148,8 @@ available. They are listed here in alphabetical order.
...
@@ -148,8 +148,8 @@ available. They are listed here in alphabetical order.
Return
a
new
"bytes"
object
,
which
is
an
immutable
sequence
of
integers
in
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
the
range
``
0
<=
x
<
256
``.
:
class
:`
bytes
`
is
an
immutable
version
of
:
class
:`
b
uffer
`
--
it
has
the
same
non
-
mutating
methods
and
the
same
indexing
:
class
:`
b
ytearray
`
--
it
has
the
same
non
-
mutating
methods
and
the
same
and
slicing
behavior
.
indexing
and
slicing
behavior
.
Accordingly
,
constructor
arguments
are
interpreted
as
for
:
func
:`
buffer
`.
Accordingly
,
constructor
arguments
are
interpreted
as
for
:
func
:`
buffer
`.
...
...
Doc/library/stdtypes.rst
View file @
9541463a
...
@@ -457,12 +457,12 @@ generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
...
@@ -457,12 +457,12 @@ generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
.. _typesseq:
.. _typesseq:
Sequence Types --- :class:`str`, :class:`bytes`, :class:`b
uffer
`, :class:`list`, :class:`tuple`, :class:`range`
Sequence Types --- :class:`str`, :class:`bytes`, :class:`b
ytearray
`, :class:`list`, :class:`tuple`, :class:`range`
===============================================================================================================
===============================================================================================================
===
There are five sequence types: strings, byte sequences, b
uffers, lists, tuple
s,
There are five sequence types: strings, byte sequences, b
yte arrays, list
s,
and range objects. (For other containers see the built-in :class:`dict`,
tuples, and range objects. (For other containers see the built-in
:class:`list`, :class:`set`, and :class:`tuple` classes, and the
:class:`
dict`, :class:`
list`, :class:`set`, and :class:`tuple` classes, and the
:mod:`collections` module.)
:mod:`collections` module.)
.. index::
.. index::
...
@@ -479,24 +479,24 @@ double quotes: ``'xyzzy'``, ``"frobozz"``. See :ref:`strings` for more about
...
@@ -479,24 +479,24 @@ double quotes: ``'xyzzy'``, ``"frobozz"``. See :ref:`strings` for more about
string literals. In addition to the functionality described here, there are
string literals. In addition to the functionality described here, there are
also string-specific methods described in the :ref:`string-methods` section.
also string-specific methods described in the :ref:`string-methods` section.
Bytes and b
uffer objects contain single bytes -- the former is immutable whi
le
Bytes and b
ytearray objects contain single bytes -- the former is immutab
le
the latter is a mutable sequence. Bytes objects can be constructed from
while
the latter is a mutable sequence. Bytes objects can be constructed from
literals too; use a ``b`` prefix with normal string syntax: ``b'xyzzy'``.
literals too; use a ``b`` prefix with normal string syntax: ``b'xyzzy'``.
To
To construct buffer objects, use the :func:`buffer
` function.
construct byte arrays, use the :func:`bytearray
` function.
.. warning::
.. warning::
While string objects are sequences of characters (represented by strings of
While string objects are sequences of characters (represented by strings of
length 1), bytes and b
uffer
objects are sequences of *integers* (between 0
length 1), bytes and b
ytearray
objects are sequences of *integers* (between 0
and 255), representing the ASCII value of single bytes. That means that for
and 255), representing the ASCII value of single bytes. That means that for
a bytes or b
uffer
object *b*, ``b[0]`` will be an integer, while ``b[0:1]``
a bytes or b
ytearray
object *b*, ``b[0]`` will be an integer, while ``b[0:1]``
will be a bytes or b
uffer
object of length 1.
will be a bytes or b
ytearray
object of length 1.
Also, while in previous Python versions, byte strings and Unicode strings
Also, while in previous Python versions, byte strings and Unicode strings
could be exchanged for each other rather freely (barring encoding issues),
could be exchanged for each other rather freely (barring encoding issues),
strings and bytes are now completely separate concepts. There's no implicit
strings and bytes are now completely separate concepts. There's no implicit
en-/decoding if you pass and object of the wrong type. A string always
en-/decoding if you pass and object of the wrong type. A string always
compares unequal to a bytes or b
uffer
object.
compares unequal to a bytes or b
ytearray
object.
Lists are constructed with square brackets, separating items with commas: ``[a,
Lists are constructed with square brackets, separating items with commas: ``[a,
b, c]``. Tuples are constructed by the comma operator (not within square
b, c]``. Tuples are constructed by the comma operator (not within square
...
@@ -504,10 +504,9 @@ brackets), with or without enclosing parentheses, but an empty tuple must have
...
@@ -504,10 +504,9 @@ brackets), with or without enclosing parentheses, but an empty tuple must have
the enclosing parentheses, such as ``a, b, c`` or ``()``. A single item tuple
the enclosing parentheses, such as ``a, b, c`` or ``()``. A single item tuple
must have a trailing comma, such as ``(d,)``.
must have a trailing comma, such as ``(d,)``.
Objects of type range are similar to buffers in that there is no specific syntax
Objects of type range are created using the :func:`range` function. They don't
to create them, but they are created using the :func:`range` function. They
support slicing, concatenation or repetition, and using ``in``, ``not in``,
don't support slicing, concatenation or repetition, and using ``in``, ``not
:func:`min` or :func:`max` on them is inefficient.
in``, :func:`min` or :func:`max` on them is inefficient.
Most sequence types support the following operations. The ``in`` and ``not in``
Most sequence types support the following operations. The ``in`` and ``not in``
operations have the same priorities as the comparison operations. The ``+`` and
operations have the same priorities as the comparison operations. The ``+`` and
...
@@ -1168,16 +1167,16 @@ Mutable Sequence Types
...
@@ -1168,16 +1167,16 @@ Mutable Sequence Types
.. index::
.. index::
triple: mutable; sequence; types
triple: mutable; sequence; types
object: list
object: list
object: b
uffer
object: b
ytearray
List and b
uffer
objects support additional operations that allow in-place
List and b
ytearray
objects support additional operations that allow in-place
modification of the object. Other mutable sequence types (when added to the
modification of the object. Other mutable sequence types (when added to the
language) should also support these operations. Strings and tuples are
language) should also support these operations. Strings and tuples are
immutable sequence types: such objects cannot be modified once created. The
immutable sequence types: such objects cannot be modified once created. The
following operations are defined on mutable sequence types (where *x* is an
following operations are defined on mutable sequence types (where *x* is an
arbitrary object).
arbitrary object).
Note that while lists allow their items to be of any type, b
uffer
object
Note that while lists allow their items to be of any type, b
ytearray
object
"items" are all integers in the range 0 <= x < 256.
"items" are all integers in the range 0 <= x < 256.
+------------------------------+--------------------------------+---------------------+
+------------------------------+--------------------------------+---------------------+
...
@@ -1271,7 +1270,7 @@ Notes:
...
@@ -1271,7 +1270,7 @@ Notes:
sequence.
sequence.
(7)
(7)
:meth:`sort` is not supported by
buffer
objects.
:meth:`sort` is not supported by
:class:`bytearray`
objects.
The :meth:`sort` method takes optional arguments for controlling the
The :meth:`sort` method takes optional arguments for controlling the
comparisons.
comparisons.
...
@@ -1305,13 +1304,13 @@ Notes:
...
@@ -1305,13 +1304,13 @@ Notes:
.. _bytes-methods:
.. _bytes-methods:
Bytes and B
uffer
Methods
Bytes and B
yte Array
Methods
------------------------
------------------------
----
.. index:: pair: bytes; methods
.. index:: pair: bytes; methods
pair: b
uffer
; methods
pair: b
ytearray
; methods
Bytes and b
uffer
objects, being "strings of bytes", have all methods found on
Bytes and b
ytearray
objects, being "strings of bytes", have all methods found on
strings, with the exception of :func:`encode`, :func:`format` and
strings, with the exception of :func:`encode`, :func:`format` and
:func:`isidentifier`, which do not make sense with these types. For converting
:func:`isidentifier`, which do not make sense with these types. For converting
the objects to strings, they have a :func:`decode` method.
the objects to strings, they have a :func:`decode` method.
...
@@ -1321,7 +1320,7 @@ Wherever one of these methods needs to interpret the bytes as characters
...
@@ -1321,7 +1320,7 @@ Wherever one of these methods needs to interpret the bytes as characters
.. note::
.. note::
The methods on bytes and b
uffer
objects don't accept strings as their
The methods on bytes and b
ytearray
objects don't accept strings as their
arguments, just as the methods on strings don't accept bytes as their
arguments, just as the methods on strings don't accept bytes as their
arguments. For example, you have to write ::
arguments. For example, you have to write ::
...
@@ -1334,7 +1333,7 @@ Wherever one of these methods needs to interpret the bytes as characters
...
@@ -1334,7 +1333,7 @@ Wherever one of these methods needs to interpret the bytes as characters
b = a.replace(b"a", b"f")
b = a.replace(b"a", b"f")
The bytes and b
uffer
types have an additional class method:
The bytes and b
ytearray
types have an additional class method:
.. method:: bytes.fromhex(string)
.. method:: bytes.fromhex(string)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment