I want to change the value of attribute pen_color in View class permanently when I call changeColor method and the value still permenant unless I call the method again with another color,
when I call changeColor method the pen_color attribute still have the same value and I don’t want such thing
Is there any way to do such thing or not ?
class View:
def __init__(self):
self.pen_color = 'red'
class Button(View):
def __init__(self):
pass
def changeColor(self):
super().__init__()
self.pen_color = 'green'
>Solution :
You should move the declaration of pen color into a class attribute rather than an instance attribute and reference it as View.pen_color.
Having done that View.pen_color will be permanent and global, but can be shadowed by self.pen_color in either View or Button instances.