typing.NamedTuple()

typing.NamedTuple(typename, fields)

Typed version of namedtuple.

Usage:

Employee = typing.NamedTuple('Employee', [('name', str), ('id', int)])

This is equivalent to:

Employee = collections.namedtuple('Employee', ['name', 'id'])

The resulting class has one extra attribute: _field_types, giving a dict mapping field names to types. (The field names are in the _fields attribute, which is part of the namedtuple API.)

doc_python
2016-10-07 17:45:57
Comments
Leave a Comment

Please login to continue.