Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdb99f1

Browse files
committed
More struct module docs and docstring tweaks.
1 parent aacfa95 commit fdb99f1

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

Doc/library/struct.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,38 @@ The module defines the following exception and functions:
3838

3939
.. function:: pack(fmt, v1, v2, ...)
4040

41-
Return a bytes containing the values ``v1, v2, ...`` packed according to the
42-
given format. The arguments must match the values required by the format
43-
exactly.
41+
Return a bytes object containing the values *v1*, *v2*, ... packed according
42+
to the format string *fmt*. The arguments must match the values required by
43+
the format exactly.
4444

4545

4646
.. function:: pack_into(fmt, buffer, offset, v1, v2, ...)
4747

48-
Pack the values ``v1, v2, ...`` according to the given format, write the
49-
packed bytes into the writable *buffer* starting at *offset*. Note that the
50-
offset is a required argument.
48+
Pack the values *v1*, *v2*, ... according to the format string *fmt* and
49+
write the packed bytes into the writable buffer *buffer* starting at
50+
position *offset*. Note that *offset* is a required argument.
5151

5252

53-
.. function:: unpack(fmt, bytes)
53+
.. function:: unpack(fmt, buffer)
5454

55-
Unpack the bytes (presumably packed by ``pack(fmt, ...)``) according to the
56-
given format. The result is a tuple even if it contains exactly one item.
57-
The bytes must contain exactly the amount of data required by the format
58-
(``len(bytes)`` must equal ``calcsize(fmt)``).
55+
Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``)
56+
according to the format string *fmt*. The result is a tuple even if it
57+
contains exactly one item. The buffer must contain exactly the amount of
58+
data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``).
5959

6060

6161
.. function:: unpack_from(fmt, buffer, offset=0)
6262

63-
Unpack the *buffer* according to the given format. The result is a tuple even
64-
if it contains exactly one item. The *buffer* must contain at least the
65-
amount of data required by the format (``len(buffer[offset:])`` must be at
66-
least ``calcsize(fmt)``).
63+
Unpack from *buffer* starting at position *offset*, according to the format
64+
string *fmt*. The result is a tuple even if it contains exactly one
65+
item. *buffer* must contain at least the amount of data required by the
66+
format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``).
6767

6868

6969
.. function:: calcsize(fmt)
7070

71-
Return the size of the struct (and hence of the bytes) corresponding to the
72-
given format.
71+
Return the size of the struct (and hence of the bytes object produced by
72+
``pack(fmt, ...)``) corresponding to the format string *fmt*.
7373

7474
.. _struct-format-strings:
7575

@@ -358,10 +358,10 @@ The :mod:`struct` module also defines the following type:
358358
Identical to the :func:`pack_into` function, using the compiled format.
359359

360360

361-
.. method:: unpack(bytes)
361+
.. method:: unpack(buffer)
362362

363363
Identical to the :func:`unpack` function, using the compiled format.
364-
(``len(bytes)`` must equal :attr:`self.size`).
364+
(``len(buffer)`` must equal :attr:`self.size`).
365365

366366

367367
.. method:: unpack_from(buffer, offset=0)
@@ -376,6 +376,6 @@ The :mod:`struct` module also defines the following type:
376376

377377
.. attribute:: size
378378

379-
The calculated size of the struct (and hence of the bytes) corresponding
380-
to :attr:`format`.
379+
The calculated size of the struct (and hence of the bytes object produced
380+
by the :meth:`pack` method) corresponding to :attr:`format`.
381381

Modules/_struct.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ PyDoc_STRVAR(s_pack_into__doc__,
16051605
\n\
16061606
Pack the values v1, v2, ... according to the format string S.format\n\
16071607
and write the packed bytes into the writable buffer buf starting at\n\
1608-
offset. Note that the offset is not an optional argument. See\n\
1608+
offset. Note that the offset is a required argument. See\n\
16091609
help(struct) for more on format strings.");
16101610

16111611
static PyObject *
@@ -1800,8 +1800,8 @@ calcsize(PyObject *self, PyObject *fmt)
18001800
PyDoc_STRVAR(pack_doc,
18011801
"pack(fmt, v1, v2, ...) -> bytes\n\
18021802
\n\
1803-
Return a bytes object containing values v1, v2, ... packed according to\n\
1804-
the format string fmt. See help(struct) for more on format strings.");
1803+
Return a bytes object containing the values v1, v2, ... packed according\n\
1804+
to the format string fmt. See help(struct) for more on format strings.");
18051805

18061806
static PyObject *
18071807
pack(PyObject *self, PyObject *args)
@@ -1834,7 +1834,7 @@ PyDoc_STRVAR(pack_into_doc,
18341834
\n\
18351835
Pack the values v1, v2, ... according to the format string fmt and write\n\
18361836
the packed bytes into the writable buffer buf starting at offset. Note\n\
1837-
that the offset is not an optional argument. See help(struct) for more\n\
1837+
that the offset is a required argument. See help(struct) for more\n\
18381838
on format strings.");
18391839

18401840
static PyObject *

0 commit comments

Comments
 (0)