When I do import foo
Python will go through the Python path (sys.path
) looking for a match, and import the first match.
But there might be more than one path that has a matching module. Is there a way of getting a list of all the matching modules?
Also, I need a method that does not actually import the package since the package may be broken such that attempting to import it results in a fatal error.
The following works even though foo
is broken:
pkgloader = pkgutil.find_loader('foo')
print(pkgloader.get_filename())
But I need something that finds all matching modules, e.g. pkgutil.find_all_loaders('foo')
.