Jan-10-2023, 09:30 PM
I don't really understand your question. Is this applicable?
All ports have an instance variable named "var". This variable is unique to the instance. Changing the instance variable does not change the class variable, and changing the class variable does not change the instance variable. The instance variable masks the class variable but does not replace it. Instances can still see the class variable though a little extra work is required.
class Bridge: var = 1 class Port(Bridge): def __init__(self, var=None): super().__init__() self.var = super().var if var is None else var def super_var(self): return super().var a = Port() b = Port(2) Bridge.var = 3 c = Port() d = Port(4) print(a.var, b.var, c.var, d.var, a.super_var())
Output:1 2 3 4 3
All ports share the same Bridge.var class variable. The class variable can be assigned different values using the class, not an instance of the class.All ports have an instance variable named "var". This variable is unique to the instance. Changing the instance variable does not change the class variable, and changing the class variable does not change the instance variable. The instance variable masks the class variable but does not replace it. Instances can still see the class variable though a little extra work is required.