Mar-30-2022, 06:28 AM
(This post was last modified: Mar-30-2022, 06:28 AM by deanhystad.)
from collections import namedtuple Point = namedtuple('Point', ['x', 'y']) p = Point(1, 2) print(p._asdict()) fields = {field:getattr(p, field) for field in p._fields} print(fields)
Output:{'x': 1, 'y': 2}
{'x': 1, 'y': 2}