Skip to content

Instantly share code, notes, and snippets.

@jizhang
Last active July 12, 2023 02:32
Show Gist options
  • Save jizhang/d2e19271b4d71eb3ef563c22c2718e01 to your computer and use it in GitHub Desktop.
Save jizhang/d2e19271b4d71eb3ef563c22c2718e01 to your computer and use it in GitHub Desktop.
def import_submodules(package) -> None:
package = importlib.import_module(package)
for _, name, is_pkg in pkgutil.iter_modules(package.__path__):
full_name = package.__name__ + '.' + name
if is_pkg:
import_submodules(full_name)
else:
importlib.import_module(full_name)
import_submodules(__package__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment