If I define a module module with the appropriate module/
directory, can I dynamically load classes from child modules such as a.py
or b.py
?
- module
----a.py
----b.py
Does it need to know the name of the class to search for? Can I set up a base class that will somehow load these children?
A basic use case is to let the user write their own code that they download. Just like rails, you can write your own controllers, views, and models in specific directories.
Code to load modules dynamically i still
def load(folder): files = {} for filename in os.listdir(folder): if (filename[0] != '_' and filename[0] != '.'): files[filename.rstrip('.pyc')] = None
I was hoping to change it to return class objects.
source share