python call abstract method implemented by child class, from parent class

29 Views Asked by At

I'm trying to do like that.

class A:
    def __init__(self):
        self.__init_first()
        self.__init_second()

    def __init_first(self):
        #do something

    @abstractmethod
    def __init_second(self):
        raise NotImplementedError()

class B(A):
    def __init__(self):
        super().__init__()

    def __init_second(self):
        #do something    

class C(A):
    def __init__(self):
        super().__init__()

    def __init_second(self):
        #do something2

b = B()
c = C()

However, it always invoke NotImplementedError. How can I use child class' __init_second function in parent class?

I searched a lot, but no answer for my question.

0

There are 0 best solutions below