I have a class a defined like this:
class a: def __init__(self, w, x, y, z): self.w = w self.x = x self.y = y self.__z = z I also have another class b which inherits a defined like this:
class b(a): def __init__(self, w, x, y, z, t): super().__init__(w, x, y, z) self.__t = t Now if I had access w, x, y from within b, I could simply do:
self.w self.x self.y But I can't do self.z or self.__z to access z. So my question is how can you access dunder values such as z from within class b
(I know python doesn't really have private variables and I could do self._a__z from within class b to access z but I'm looking for methods which would allow me to just do something like self.z to access z from inside b)
_a__zis the only way to do it.self.zthen don't use double underscore name mangling. You are trying to have your cake and eat it too.zis meant to be accessible inbthen it should not be private, as @juanpa.arrivillaga suggested. 2. Ifzis meant to be partially accessible (e.g. read-only) inbthen you can usegetters and/orsetters just like in other OOP languages.