I have a parent class that provides abstract functions for manipulating hardware, and a directory full of classes that subclass this parent class, and provide hardware-specific implementation (e.g. x86 functions, ARM functions...). I am looking for a Pythonic way to import the files in the directory, and instantiate them.
At the moment the parent class is in the top level directory, and the files with the child classes in a subdirectory. This can be changed, for style or ease of implementation.
Is it preferable to load all the hardware-specific classes in the subdirectory by defining a list of them in a configuration file, and iterating over that to import them? Or would it be better (more Pythonic) to do it automatically with importlib? Or does it not matter?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…