If I have a class say:
class BaseClassOnly():
def __init__(self):
self._foo = None
def do_stuff(self):
print("doing stuff with foo" + self._foo)
I want to force all classes derived from BaseClassOnly to provide a value for 'self._foo' so that the inherited function do_stuff() will be able to use it. Is there a way to ensure if a class that inherits from BaseClassOnly with result in an error if the variable self._foo is not set in init()?
If you assume that the child classes will call the base class's
__init__(), you could usehasattr()to check.