【Python】namedtupple

>>>from collections import *
>>> # Basic example
>>> Point = namedtuple('Point', ['x', 'y'])
>>> p = Point(11, y=22)     # instantiate with positional or keyword arguments
>>> p[0] + p[1]             # indexable like the plain tuple (11, 22)
33
>>> x, y = p                # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y               # fields also accessible by name
33
>>> p                       # readable __repr__ with a name=value style
Point(x=11, y=22)

8.3. collections — コンテナデータ型 — Python 3.6.1 ドキュメント


tensorflowのdata_input()でMNISTを読み込んだ時のMNISTのデータ型

print(type(mnist))
<class 'tensorflow.contrib.learn.python.learn.datasets.base.Datasets'>

TensorFlow内での定義

Datasets = collections.namedtuple('Datasets', ['train', 'validation', 'test'])#line 37

github.com