Top "Namedtuple" questions

namedtuple is a data structure provided by the Python collections module.

Python: Extending a predefined named tuple

I have the following named tuple: from collections import namedtuple ReadElement = namedtuple('ReadElement', 'address value') and then I want the …

python python-2.7 namedtuple
Adding docstrings to namedtuples?

Is it possible to add a documentation string to a namedtuple in an easy manner? I tried from collections import …

python docstring namedtuple
Data Classes vs typing.NamedTuple primary use cases

Long story short PEP-557 introduced data classes into Python standard library, that basically can fill the same role as collections.…

python namedtuple pep python-3.7 python-dataclasses
Subclassing collections namedtuple

Python's namedtuple can be really useful as a lightweight, immutable data class. I like using them for bookkeeping parameters rather …

python namedtuple
How do I avoid the "self.x = x; self.y = y; self.z = z" pattern in __init__?

I see patterns like def __init__(self, x, y, z): ... self.x = x self.y = y self.z = z ... quite …

python python-2.7 python-decorators namedtuple python-attrs
Printing named tuples

In Python 2.7.1 I can create a named tuple: from collections import namedtuple Test = namedtuple('Test', ['this', 'that']) I can populate …

python namedtuple
Is there an elegant way to use struct and namedtuple instead of this?

I'm reading a binary file made up of records that in C would look like this: typedef _rec_t { char …

python struct binaryfiles namedtuple
What's the difference between enum and namedtuple?

I would like to know what are the differences between enum and namedtuple and when one should use one over …

python python-3.x enums namedtuple
Using namedtuple._replace with a variable as a fieldname

Can I reference a namedtuple fieldame using a variable? from collections import namedtuple import random Prize = namedtuple("Prize", ["left", "right"]) …

python namedtuple
What are the main differences of NamedTuple and TypedDict in Python / mypy

It seems to me that NamedTuple and TypedDict are fairly similar and the Python developers themselves recognized that. Concerning the …

python dictionary types namedtuple mypy