Created
May 30, 2023 23:48
-
-
Save loredous/d5f53a66c9141f0dd42fecc72267b8b6 to your computer and use it in GitHub Desktop.
Example of dynamic loading of Python modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_components(): | |
dirname = "components" | |
for importer, package_name, _ in pkgutil.iter_modules([dirname]): | |
full_package_name = '%s.%s' % (dirname, package_name) | |
if full_package_name not in sys.modules: | |
module = importer.find_module(package_name | |
).load_module(package_name) | |
modules.append(module) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment