Jul-09-2018, 12:22 PM
I have this code:
I don't want this. Is there a way of accessing parent variables and methods without using
Thanks!
class Parent: def __init__(self): self.name = "Parent" def create_child(self): x = Child() class Child(Parent): def __init__(self): Parent.__init__(self) print(self.name) x = Parent() x.name = "Parent2" x.create_child() print(x.name)Which Outputs:
Output:Parent
Parent2
It is creating a new instance of Parent
when Child
is called.I don't want this. Is there a way of accessing parent variables and methods without using
object.__init__(self,*args,**kwargs)
?Thanks!