Skip to content

Conversation

@rydesun
Copy link
Contributor

@rydesun rydesun commented May 27, 2017

这里并非是错误,直接导入当前目录下的模块的方式叫隐式相对导入,在 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.

@xianhu xianhu merged commit 97954d7 into xianhu:master May 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants