Re:Improving your code readability with namedtuples
by kdazzle on Saturday October 31, 2015 @01:43PM
(#10483400)
Not sure why you wouldn't just use a class in this case...
[ Parent
| on HN ]
Re:Improving your code readability with namedtuples
by Scarblac on Saturday October 31, 2015 @02:11PM
(#10483518)
Immutability.
Both in a "eat your vegetables" sense (it's good in general to have immutable data structures where possible, that's one cause of bugs eliminated), and for practical reasons such as using them as keys of dictionaries, and as elements of sets.
You can also _inherit_ from namedtuples, in case you want to add methods.
Re:Improving your code readability with namedtuples
by nottednelson on Saturday October 31, 2015 @02:15PM
(#10483532)
Yay, like locked named ranges in a basically-just-a-clunky-functional-programming-environment spreadsheet. :)
Re:Improving your code readability with namedtuples
by maxerickson on Saturday October 31, 2015 @01:47PM
(#10483418)
collections.namedtuple is just a factory for a particular sort of class.