开发者

Problem understanding Importer Protocol in Python

开发者 https://www.devze.com 2023-02-18 09:02 出处:网络
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开发

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号