Python中导入器协议的理解问题

2024-03-29 09:17:25 发布

您现在位置:Python中文网/ 问答频道 /正文

根据http://www.python.org/dev/peps/pep-0302/,我在理解导入程序协议时遇到了一些问题。finder.find_module(fullname, path=None)fullname参数是否应该从不包含一个。(点)?你知道吗

也就是说,如果要查找模块abc.efg.hij,必须调用finder.find_module('hij', path='abc.efg')。调用finder.find_module('abc.efg.hij')绝对不正确。你知道吗

是这样吗?你知道吗


Tags: pathorgdev程序httpfinderwwwfind
1条回答
网友
1楼 · 发布于 2024-03-29 09:17:25

不,只是说import abc.efg.hij最终会在导入过程的不同阶段产生3个不同的find_module调用:

find_module("abc", None)
find_module("abc.efg", abc.__path__)
find_module("abc.efg.hij", abc.efg.__path__)

浏览importlib文档也可能会引起您的兴趣: http://docs.python.org/py3k/library/importlib#importlib.abc.Finder.find_module

相关问题 更多 >