I’m toying with the idea of creating a fixed length list. I don’t mean only intialising, but setting it so you can’t change the length.
It seems that I might be able to create a sub class and disable the dunder functions which change the size of the list. Something like this:
class FixedList(list):
# disable __append__ etc
data = FixedList(['apple','banana','cherry','donut','etc']
I’ve tried:
class FixedList(list):
def __append__(self):
pass
but that doesn’t work — I can still append a new value.
Is it possible to disable a dunder function like this? (If somebody wants to suggest a better way of doing this, I’m listening …)