Importing by file name

Ian Kelly ian.g.kelly at gmail.com
Sun Nov 24 12:37:00 CET 2013


On Sun, Nov 24, 2013 at 4:05 AM, Chris Angelico <rosuav at gmail.com> wrote:
> Undocumented... that explains why I didn't know about it! But that
> does appear to be what I'm looking for, so is there some equivalent
> planned as a replacement?

Hmm, playing around with importlib a bit, this seems to work:

from importlib import find_loader
loader = find_loader('spam', ['/path/to'])
if loader is not None:
    module = loader.load_module()

The path passed to find_loader is searched instead of sys.path.



More information about the Python-list mailing list