I'm trying to understand the following code from the MIT python class. When i create an object of the class intSet as follows i run into some trouble with one of the attributes.
s=intSet()
and try
s.vals()
I get the following error
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
s.vals()
TypeError: 'list' object is not callable
why is this? I've been told i shouldn't try s.vals directly because of data hiding, when i try s.vals the correct list is returned but i get an error when trying s.vals(). Can someone explain this error? I'm new to both OOP and python so i apologise for my poor questioning. Any help is greatly appreciated.
s.valsis a list, which isn't callable.self._vals = []. This is privacy by convention, no one is actually prevented from accessing your attribute. But people who use your code base know "this is an implementation detail and not a guarantee, don't use this, and if you do, know you can't rely on this behavior". Also, Python generally is written using "snake_case" instead of "camelCase".