5 ms·
I don't get your point about unpacking yet to be honest. Both your code examples work fine with namedtuples I think. Adding additional attributes is better in t
by m_mueller 9y ago
I don't get your point about unpacking yet to be honest. Both your code examples work fine with namedtuples I think. Adding additional attributes is better in the second example, which is why it is to be preferred, but that works with namedtuples as far as I understand.
- maxerickson 9y agoAdding a member to the tuple requires updating all code that unpacks it. Adding an attribute doesn't impact any code that doesn't use the attribute.
- m_mueller 9y agoYes, that's why you usually don't use unpacking for a namedtuple. This works just fine without me adding additional 3rd party packages: > from collections import namedtuple > Point = namedtuple('Point', ['x', 'y']) > points = [Point(3,4), Point(5,2)] > for p in points: > print(p.x, p.y)