Why does importing a python module not import nested modules?

后端 未结 5 2200
误落风尘
误落风尘 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 04:59

    It's by design. The package has the option to import the nested package in its __init__.py, then, you would be able to access the nested package without problems. It's a matter of choice for the package writer, and the intent is to minimize the amount of code that you probably won't use.

提交回复
热议问题