Martin Panter added the comment:
My use case is for Readline auto-completion, to list submodules of a package
given by the user, without importing anything unnecessary. The original code is
compatible with Python 2, but I am also writing a patch for 3.6 that wouldn't
need that. The original implementation is like this pseudocode:
def list_submodules(package):
# Ensure it is a package before loading or importing it
for name in parent_packages:
loader = pkgutil.find_loader(name)
assert loader.is_package()
# Could call importlib.import_module(), but this seemed easier because I
already have the loader:
package = loader.load_module(name)
# The only reason I want to load the module:
search_path = package.__path__
return pkgutil.iter_modules(search_path)
Thanks for your feedback Brett. I have changed over to
importlib.import_module(), and will accept that this is just a quirk of the low
level import stuff.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25372>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com