Why does importing a python module not import nested modules?

后端 未结 5 2190
误落风尘
误落风尘 2020-12-10 04:37

If I do this:

import lxml 

in python, lxml.html is not imported. For instance, I cannot call the lxml.html.parse()

5条回答
  •  不思量自难忘°
    2020-12-10 05:01

    lxml is called a package in Python, which is a hierachical collections of modules. Packages can be huge, so they are allowed to be selective about what is pulled in when they are imported. Otherwise everybody would have to import the full hierarchy, which would be quite a waste of resources.

提交回复
热议问题