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

    Jun 4, 2010 · Named tuples are basically easy-to-create, lightweight object types. Named tuple instances can be referenced using object-like variable dereferencing or the standard tuple syntax. …

  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 pull 105287 …

  3. Named tuple and default values for optional keyword arguments

    Jul 6, 2012 · In all versions of Python, if you set fewer default values than exist in the namedtuple, the defaults are applied to the rightmost parameters. This allows you to keep some arguments as …

  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 code will …

  5. Data Classes vs typing.NamedTuple primary use cases

    Aug 3, 2018 · PEP-557 introduced data classes into Python standard library, that basically can fill the same role as collections.namedtuple and typing.NamedTuple. And now I'm wondering how to …

  6. python - How to access a field of a namedtuple using a variable for the ...

    Jun 19, 2017 · How to access a field of a namedtuple using a variable for the field name? Asked 8 years, 8 months ago Modified 4 years, 5 months ago Viewed 58k times

  7. python - How to cast tuple into namedtuple? - Stack Overflow

    I'd like to use namedtuples internally, but I want to preserve compatibility with users that feed me ordinary tuples. from collections import namedtuple tuple_pi = (1, 3.14, "pi") #Normal

  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 work with …

  9. python - Pythonic way to convert a dictionary into namedtuple or ...

    nt = namedtuple.from_dict() ? UPDATE: as discussed in the comments, my reason for wanting to convert my dictionary to a namedtuple is so that it becomes hashable, but still generally useable like …

  10. python - A way to subclass NamedTuple for purposes of typechecking ...

    z: str The module is new in Python 3.7 but you can pip install dataclasses the backport on Python 3.6. The above defines two immutable classes with x and y attributes, with the BaseExtended class …