About 954,000 results
Open links in new tab
  1. types - What are "named tuples" in Python? - Stack Overflow

    Jun 4, 2010 · What are named tuples? A named tuple is a tuple. It does everything a tuple can. But it's more than just a tuple. It's a specific subclass of a tuple that is programmatically …

  2. python - Type hints in namedtuple - Stack Overflow

    Dec 14, 2015 · ^^ While the keyword-argument syntax mentioned by @MarkedasDuplicate still works (tested on Python 3.10.9 (tags/v3.10.9:1dd9be6)), it was removed from the docstrings in …

  3. Named tuple and default values for optional keyword arguments

    Jul 6, 2012 · Since you are using namedtuple as a data class, you should be aware that python 3.7 will introduce a @dataclass decorator for this very purpose -- and of course it has default …

  4. namedtuple vs NamedTuple in Python - Stack Overflow

    The type generated by subclassing typing.NamedTuple is equivalent to a collections.namedtuple, but with __annotations__, _field_types and _field_defaults attributes added. The generated …

  5. python - Convert a namedtuple into a dictionary - Stack Overflow

    This is a documented method of namedtuples, i.e. unlike the usual convention in python the leading underscore on the method name isn't there to discourage use. Along with the other …

  6. Data Classes vs typing.NamedTuple primary use cases

    Aug 3, 2018 · Long story short PEP-557 introduced data classes into Python standard library, that basically can fill the same role as collections.namedtuple and typing.NamedTuple. And now …

  7. python - how do I add fields to a namedtuple? - Stack Overflow

    Mar 10, 2013 · I am working with a list of namedtuples. I would like to add a field to each named tuple after it has already been created. It seems I can do that by just referencing it as an …

  8. python - When and why should I use a namedtuple instead of a …

    Mar 26, 2012 · The standard library namedtuple class looks to me like a way to make tuples more like dictionaries. How do namedtuples compare to dicts? When should we use them? Do they …

  9. Serializing a Python namedtuple to json - Stack Overflow

    May 6, 2011 · What is the recommended way of serializing a namedtuple to json with the field names retained? Serializing a namedtuple to json results in only the values being serialized …

  10. python - Inheriting from a namedtuple base class - Stack Overflow

    This question is asking the opposite of Inherit namedtuple from a base class in python , where the aim is to inherit a subclass from a namedtuple and not vice versa. In normal inheritance, this …