3 ms·
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.
by IgorPartola 9y ago
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.
- yes_or_gnome 9y agoYou 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 https://stackoverflow.com/questions/472000/usage-of-slots
- IgorPartola 9y agoRe: storing mutable objects, yea but tuples do that too: t = ({}, 1) t[0]['foo'] = 'bar'