xianhu / LearnPython

以撸代码的形式学习Python
https://github.com/xianhu/LearnPython
7.61k stars 3.95k forks source link

Update python_base.py #23

Closed rydesun closed 7 years ago

rydesun commented 7 years ago

这里并非是错误,直接导入当前目录下的模块的方式叫隐式相对导入,在 Python2 中可用。但因为存在覆盖导入的问题,在 Python3 中禁止了隐式相对导入。

PEP 328:

Imports can be ambiguous in the face of packages; within a package, it's not clear whether import foo refers to a module within the package or some module outside the package. (More precisely, a local module or package can shadow another hanging directly off sys.path .)

... it is proposed that all import statements be absolute by default (searching sys.path only) with special syntax (leading dots) for accessing package-relative imports.

PEP 404:

In Python 3, implicit relative imports within packages are no longer available - only absolute imports and explicit relative imports are supported. In addition, star imports (e.g. from x import * ) are only permitted in module level code.