I've been working on a school OOP python project and I stumbled upon this problem:
class AList:
def __init__(self, l):
self.__a_private_attribute = l
@property
def l(self):
return self.__a_private_attribute
if __name__ == '__main__':
li = AList([0])
li.l[0] = "this shouldn't work"
print(li.l)
The output of this is
["this shouldn't work"]
How am I able to call methods on a list that does only have a getter and no setter. I know that privacy is not a strength of python, but I can't figure out why I can assign items in a list.
I was expecting a AttributeError to be raised by python because I am trying to reassign something without a setter. Does anyone know why am I not raising an Error?