1

If I have a class like this:

class A(object):
    def __init__(self):
         self.dynamic_objects = []

And a subfolder in the same location with a variable amount of files each with one class that are child of the same parent class (in other words they have the same methods and variables):

class B(Parent):
     def run(self):
         # logic here
         return

How could I go about making the list of dynamic_objects in class A automatically populate one object for each file in the subfolder? So if my file structure is like this:

a.py
     /subfolder
         b.py
         c.py
         d.py

How could I make it so that the dynamic_objects list is filled with one B object, one C object, and one D object without hardcoding it in that list but just pointing it to the directory? Is this possible?

I want to do this in my application so that anyone who wants to extend the functionality of the app can just worry about making a class with a run method in the subfolder without having to edit a.py

Spencer Sutton
  • 2,907
  • 2
  • 18
  • 19
  • 1
    See [Importing classes from different files in a subdirectory](https://stackoverflow.com/questions/5134893/importing-classes-from-different-files-in-a-subdirectory) – martineau Aug 28 '19 at 21:14

0 Answers0