Re:Redesigning Python's named tuples
by IgorPartola on Friday September 01, 2017 @11:14AM
(#15149068)
Wouldn't it be so convenient if Python provided a way to define immutable classes? Also, you can always provide a `draw_point(*p.args)` which isn't bad at all.
[ Parent
| on HN ]
Re:Redesigning Python's named tuples
by yes_or_gnome on Friday September 01, 2017 @12:13PM
(#15149767)
You can get close. Set __slots__ and then define each as a property with no setter and no deleter. However, an object can still be modified if it stores a mutable object (list, dict) and, while I'm not in front of a computer atm,I believe you can overwrite __slots__ to do whatever.
Here's an SO answer that explains more than I'll ever know about slots. https://stackoverflow.com/questions/472000/usage-of-slots
Re:Redesigning Python's named tuples
by IgorPartola on Friday September 01, 2017 @12:15PM
(#15149795)
Re: storing mutable objects, yea but tuples do that too:
t = ({}, 1)
t[0]['foo'] = 'bar'