Feb-11-2020, 03:56 PM
This works, but is this pythonic if I instantiate MyBord class in different classes? For example in class A, in class B (which is also instantiated form class A and in different module), class C, ...?
(Feb-07-2020, 09:38 AM)Gribouillis Wrote: You can use @property to define attributes that cannot be written. For example
class MyBorg: __shared = { '_alert_one': [], '_alert_two': [], } def __init__(self): self.__dict__ = self.__shared @property def alert_one(self): return self._alert_one @property def alert_two(self): return self._alert_two b = MyBorg() b.alert_one.append('spam') c = MyBorg() print(c.alert_one) # <--- prints ['spam'] # One cannot set the attribute # c.alert_one = 'bar' # raises AttributeError