2021年3月23日星期二

How to have grandchild inherit from aunt/uncle class in python?

In python this is possible:

class A():      class B():          class C():              def __init__(self):                  self.another_child = A.AnotherChildOfA()                  self.test = self.another_child.test        class AnotherChildOfA():          def test(self):              print('inherited this method')    c_object = A.B.C()  c_object.test()  

'inherited this method'

but not this:

class A():      class B():          class C(A.AnotherChildOfA):              pass        class AnotherChildOfA():          def test():              print('inherited this method')    c_object = C()  c.test()  

Error: "A" not defined.

Why is this, and is there some way to do the later, i.e. grandchild class inheriting from child class that is its parent's sibling?

https://stackoverflow.com/questions/66773394/how-to-have-grandchild-inherit-from-aunt-uncle-class-in-python March 24, 2021 at 09:08AM

没有评论:

发表评论