Skip to content

Instantly share code, notes, and snippets.

@ntessore
Last active September 29, 2022 22:47
Show Gist options
  • Save ntessore/9da75daa573b83498ed7d259d2181f87 to your computer and use it in GitHub Desktop.
Save ntessore/9da75daa573b83498ed7d259d2181f87 to your computer and use it in GitHub Desktop.
Automatically import all packages from a Python namespace package
# author: Nicolas Tessore <n.tessore@ucl.ac.uk>
# license: MIT
'''meta-module that imports all modules from its namespace package
Package this module in your namespace. Then use ``import mynamespace.all`` and
every module in the namespace will be available under the import.
'''
(lambda: [__import__(_.name) for _ in __import__('pkgutil').iter_modules(__import__(__package__).__path__, __package__ + '.')])() # noqa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment