You aren't supposed to access class' attributes that start with two underscores (and don't end with two underscores) from outside that class. This is a bit similar to private
class members in C++, for example: there you have no way of accessing such attributes, but Python doesn't have this exact mechanism, but it has the one described above, which works similarly, but still does let you access such attributes, but in an obscure manner:
>>> class Test:
... __data = 5
...
>>> Test.__data
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: type object 'Test' has no attribute '__data'
>>> dir(Test)
['_Test__data', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
>>> Test._Test__data
5
As you can see, the name of the attribute __data
has been changed to _Test__data
, but one can still access it. The same thing happens in your code. In general, the real name of such double-underscored attribute will be changed to _ClassName__AttributeName
.
In your case that would be LabTestRepository._LabTestRepository__list_of_hospital_lab_ids
.
As you can see, this doesn't apply to attributes with two underscores both at the beginning and the end, however:
>>> class Test:
... def __test__():
... print('hello')
...
>>> Test.__test__()
hello