summaryrefslogtreecommitdiff
path: root/Doc/glossary.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-09-11 19:49:02 -0700
committerGitHub <noreply@github.com>2019-09-11 19:49:02 -0700
commiteb494b470d36e4951859fc0b89c1fa50006fe84f (patch)
tree2defd9c32a3c83dd720b80fa21efe0108e441cc6 /Doc/glossary.rst
parent39de95b746c990e6a2fe9af5fad01747f58b2e5f (diff)
downloadcpython-git-revert-15895-named_tuple_concept.tar.gz
Revert "bpo-38096: Clean up the "struct sequence" / "named tuple" docs (GH-15895)"revert-15895-named_tuple_concept
This reverts commit 7117074410118086938044c7a4ef6846ec1662b2.
Diffstat (limited to 'Doc/glossary.rst')
-rw-r--r--Doc/glossary.rst41
1 files changed, 19 insertions, 22 deletions
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index 84d0fcab9d..0f2a3a1fdf 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -739,28 +739,17 @@ Glossary
also :term:`immutable`.
named tuple
- The term "named tuple" applies to any type or class that inherits from
- tuple and whose indexable elements are also accessible using named
- attributes. The type or class may have other features as well.
-
- Several built-in types are named tuples, including the values returned
- by :func:`time.localtime` and :func:`os.stat`. Another example is
- :data:`sys.float_info`::
-
- >>> sys.float_info[1] # indexed access
- 1024
- >>> sys.float_info.max_exp # named field access
- 1024
- >>> isinstance(sys.float_info, tuple) # kind of tuple
- True
-
- Some named tuples are built-in types (such as the above examples).
- Alternatively, a named tuple can be created from a regular class
- definition that inherits from :class:`tuple` and that defines named
- fields. Such as class can be written by hand or it can be created with
- the factory function :func:`collections.namedtuple`. The latter
- technique also adds some extra methods that may not be found in
- hand-written or built-in named tuples.
+ Any tuple-like class whose indexable elements are also accessible using
+ named attributes (for example, :func:`time.localtime` returns a
+ tuple-like object where the *year* is accessible either with an
+ index such as ``t[0]`` or with a named attribute like ``t.tm_year``).
+
+ A named tuple can be a built-in type such as :class:`time.struct_time`,
+ or it can be created with a regular class definition. A full featured
+ named tuple can also be created with the factory function
+ :func:`collections.namedtuple`. The latter approach automatically
+ provides extra features such as a self-documenting representation like
+ ``Employee(name='jones', title='programmer')``.
namespace
The place where a variable is stored. Namespaces are implemented as
@@ -1043,6 +1032,14 @@ Glossary
an :term:`expression` or one of several constructs with a keyword, such
as :keyword:`if`, :keyword:`while` or :keyword:`for`.
+ struct sequence
+ A tuple with named elements. Struct sequences expose an interface similar
+ to :term:`named tuple` in that elements can be accessed either by
+ index or as an attribute. However, they do not have any of the named tuple
+ methods like :meth:`~collections.somenamedtuple._make` or
+ :meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences
+ include :data:`sys.float_info` and the return value of :func:`os.stat`.
+
text encoding
A codec which encodes Unicode strings to bytes.