前导
相信你在使用xpath解析时,在创建etree对象时,会有一个疑问,为什么import xml,xml.etree.HTML()报错,而from xml import etree却创建正常
包
长话短说,因为xml包里的__init__.py文件里没有定义要导入etree
init.py 文件的主要作用:导入该包内的其他模块。
import 包名 只能导入包中__init__.py 文件中定义的内容,在__init__.py中未定义的内容:如类、函数、变量等,则不能导入。
如果要导入可以使用:import xml.etree
如需了解关于包更多详细的信息可以查看下面几个帖子:
https://blog.csdn.net/any1where/article/details/128321249
https://blog.csdn.net/weixin_37721058/article/details/103266177
https://blog.csdn.net/qq_43428929/article/details/126135217
https://blog.csdn.net/weixin_47702737/article/details/121702647