Difference in package importing between Python 2.7 and 3.4

倖福魔咒の 提交于 2019-11-29 03:47:42

Python 3 uses absolute imports (see PEP 328 as @user2357112 points out). The short of it is that Python 3 searches from the root of each sys.path entry, rather than first consulting the module's directory as if it were a prepended entry in sys.path.

To get the behavior you want you can either:

  • Use relative imports explicitly: from . import world in the hello package
  • Use an absolute import: import hello.world
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!