summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/collections.rst2
-rw-r--r--Doc/library/struct.rst10
2 files changed, 11 insertions, 1 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index a5cffdd..5035ac9 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -113,7 +113,7 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
Since some set operations create new sets, the default mixin methods need
a way to create new instances from an iterable. The class constructor is
assumed to have a signature in the form ``ClassName(iterable)``.
- That assumption is factored-out to a single internal classmethod called
+ That assumption is factored-out to an internal classmethod called
:meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set.
If the :class:`Set` mixin is being used in a class with a different
constructor signature, you will need to override :meth:`from_iterable`
diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst
index a1832a1..282483d 100644
--- a/Doc/library/struct.rst
+++ b/Doc/library/struct.rst
@@ -216,6 +216,16 @@ end, assuming longs are aligned on 4-byte boundaries. This only works when
native size and alignment are in effect; standard size and alignment does not
enforce any alignment.
+Unpacked fields can be named by assigning them to variables or by wrapping
+the result in a named tuple::
+
+ >>> record = 'raymond \x32\x12\x08\x01\x08'
+ >>> name, serialnum, school, gradelevel = unpack('<10sHHb', record)
+
+ >>> from collections import namedtuple
+ >>> Student = namedtuple('Student', 'name serialnum school gradelevel')
+ >>> Student._make(unpack('<10sHHb', s))
+ Student(name='raymond ', serialnum=4658, school=264, gradelevel=8)
.. seealso::