3 ms·
Tuples are read-only.
by mixmastamyk 9y ago
Tuples are read-only.
- weberc2 9y agoAh, of course. Good point. I tend to write things in an immutable style, so I don't usually pay attention to this.
- silviogutierrez 9y agoI see immutability as a feature. There are uses cases for mutability, but it should be opt-in, not opt-out. So I'm not loving the fact that "frozen" (the mutability param for data classes) defaults to False.
- weberc2 9y agoI agree, which is part of the reason I think I'd be inclined to derive from NamedTuple and forego data classes.
- icebraining 9y agoPython is very much not immutable by default, it'd be weird to subvert it in a specific case.
- caioariede 9y agoAlso, AFAIK you cannot add methods to NamedTuple, making it much less flexible than data classes.
- kevinmgranger 9y agoOne of the examples in the documentation uses a method. https://docs.python.org/3/library/typing.html#typing.NamedTuple https://docs.python.org/3/library/typing.html#typing.NamedTu...
- caioariede 9y agoYeah, you're right. You just cannot overwrite __init__: > AttributeError: Cannot overwrite NamedTuple attribute __init__