The from form uses a slightly more complex process:
find the module specified in the from clause, loading and initializing it if necessary;
for each of the identifiers specified in the import clauses:
check if the imported module has an attribute by that name
if not, attempt to import a submodule with that name and then check the imported module again for that attribute
if the attribute is not found, ImportError is raised.
otherwise, a reference to that value is stored in the local namespace, using the name in the as clause if it is present, otherwise using the attribute name
bs4.BeautifulSoup
不是子模块,而是类。你可以在^{你可以看到它是这样一个类:
…您可以使用^{} 模块中的函数看到它来自哪个文件,例如:
语法
from X import Y
可以做两件不同的事情:Y
是X
中的类、函数或其他名称,它将该值作为Y
从模块X
导入全局变量。你知道吗Y
是包X
下的子模块,它会将该子模块作为模块Y
导入全局。你知道吗有关详细信息,请参见文档中的The import system:
相关问题 更多 >
编程相关推荐