Inheritance
A Child class can inherit variables and methods from a Parent class.
class Parent(object):
def __init__(self, argP1, argP2):
self.argP1 = argP1
self.argP2 = argP2
class Child(Parent):
def __init__(self, argP1, argP2, argC1):
Parent.__init__(self, argP1, argP2)
self.argC1 = argC1
class SuperChild(Parent):
def __init__(self, argP1, argP2, argC1):
super(SuperChild, self).__init__(argP1, argP2)
self.argC1 = argC1
Using super().__init__()
is a more reliable and forward compatible way of inheriting.
Class and Static Method
A class method allows you to call a class within the function. The class should have @classmethod
before it, and the first argument in a class method must be a call to the class itself.
A static method allows you to package related functions that don't need to be called on a class or instance. The class should have @staticmethod
before it, and the arguments can be empty.
@classmethod
def get_instances(cls):
yield cls.__refs__
@staticmethod
def get_allowable():
return allowable