Problem understanding Importer Protocol in Python
I'm having some trouble understanding the Importer Protocol as per http://www.python.org/dev/peps/pep-0302/. Should the fullname
argument of finder.find_module(fullname, path=None)
never include a开发者_StackOverflow . (dot)?
That is, if you want to find module abc.efg.hij
, you must call finder.find_module('hij', path='abc.efg')
. Calling finder.find_module('abc.efg.hij')
would be absolutely incorrect.
Is this correct?
No, it is just saying that import abc.efg.hij
will eventually result in 3 different find_module
calls at various stages of the import process:
find_module("abc", None)
find_module("abc.efg", abc.__path__)
find_module("abc.efg.hij", abc.efg.__path__)
Exploring the importlib documentation may also be of interest to you: http://docs.python.org/py3k/library/importlib#importlib.abc.Finder.find_module
精彩评论