import a.b also imports a?

后端 未结 4 1229
故里飘歌
故里飘歌 2021-02-20 03:26

When I import a subpackage in a package, can I rely on the fact that the parent package is also imported ?

e.g. this works

python -c \"import os.path; pr         


        
4条回答
  •  忘了有多久
    2021-02-20 04:11

    Yes, you can rely on it always working. Python has to include os in the namespace for os.path to work.

    What won't work is using the from os import path notation. In that case, the os module is not brought into the namespace, only path.

提交回复
热议问题