Just use the property and the hidden attribute (with a single underscore prefix).
Simple properties are read-only!
>>> class Test (object): ... @property ... def bar(self): ... return self._bar ... >>> t = Test() >>> t._bar = 2 >>> t.bar 2 >>> t.bar = 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: can't set attribute
Double underline hiding is not used to hide the implementation, but to make sure that you do not encounter subclass attributes; consider mixin, for example, it must be very careful!
If you just want to hide the attribute, use one underscore. And as you can see, there is no extra magic to add - if you do not define the set function, your property is as read-only as the return value of the method.
u0b34a0f6ae
source share