import a.b also imports a?

后端 未结 4 1227
故里飘歌
故里飘歌 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:14

    It works and it is reliable. What happens under the hood is when you do

    import os.path
    

    then os gets imported and then os.path.

提交回复
热议问题