Answer the question
In order to leave comments, you need to log in
How to call from the parent class to the static-function of the child?
I had such a task:
There is an abstract class
class BaseClass:
@staticmethod
def get_prefix():
raise Exception('Переопределите этот метод в дочернем классе')
@staticmethod
def get_string_with_prefix(string=''):
return BaseClass.get_prefix() + string
class ChildClass(BaseClass):
@staticmethod
def get_prefix():
return 'child_class_prefix_'
Answer the question
In order to leave comments, you need to log in
Use @classmethod
class BaseClass:
@classmethod
def get_prefix(cls):
raise NotImplemented('Переопределите этот метод в дочернем классе')
@classmethod
def get_string_with_prefix(cls, string=''):
return cls.get_prefix() + string
class ChildClass(BaseClass):
@classmethod
def get_prefix(cls):
return 'child_class_prefix_'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question