I’ve written some code that contains a main and a number of subclasses that inherit variables from a superclass.
E.g.
class superclass(object):
def __init__(self, var1, var2):
self.var1 = var1
self.var2 = var2
class subclass1(superclass):
def method1(self):
pass
class subclass2(superclass):
def method1(self):
pass
The main isn’t shown, nor an option factory which is used to choose the subclass to call, but hopefully the info given will be sufficient.
I wish to convert those classes to standalone modules that can be imported.
It is expected that additional subclasses will be written in the future so I was wondering if it is possible to save each subclass and the superclass as seperate modules and that the subclasses will still be able to use/have access too the superclass variables and definitions.
The reasoning behind this is to simplify the writing of any future subclasses. Meaning they can be written as a stand alone module and the previous subclasses and the superclass don’t have to be touched as part of the development, but they will still be able to use the suberclasses variables and definitions.
I’m not sure how it would work or if it can be done that way. Whether I just save all the classes as superclass.py, subclass1.py and subclass2.py and import them all?????
Hope that made sense.
Thanks.
Yes, its totally possible. Just don’t forget to import superclass in the subclass file: