I need to to dynamically import identically named classes from files in a subfolder. The classes have different implementations in every file. After the import I need to create an instance of each class and store them in a data structure so I can invoke each function in thee instances.
folder structure:
./main.py
./players/player1.py
./players/player2.py
./players/player3.py
./players/player4.py
player1.py
class PlayerClass():
def doStuff():
stuff implementation 1
player2.py
class PlayerClass():
def doStuff():
stuff implementation 2
So main.py will import all PlayerClasses from these files and create once instance each to then be able to call functions like doStuff form each instance. Something like:
importedClasses[0].doStuff()
I have managed to extract file names but I can't get the import to work from a subfolder and I can't import them as unique objects and store them in a list or similar either.