Skip to content

Instantly share code, notes, and snippets.

@loredous
Created May 30, 2023 23:48
Show Gist options
  • Save loredous/d5f53a66c9141f0dd42fecc72267b8b6 to your computer and use it in GitHub Desktop.
Save loredous/d5f53a66c9141f0dd42fecc72267b8b6 to your computer and use it in GitHub Desktop.
Example of dynamic loading of Python modules
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