开发者

python: What's the rationale behind not allowing * in relative imports?

What's the rationale behind not allowing * in relative imports? e.g.

from ..new_tool import *

or doing a relative import directly:

import ..new开发者_Go百科_tool


The reason the latter is prohibited is that ..new_tool is not usable in an expression (PEP 328):

The reason import .foo is prohibited is because after

    import XXX.YYY.ZZZ

then XXX.YYY.ZZZ is usable in an expression. But

    .moduleY

is not usable in an expression.

Since *-imports should only ever be a quick hack while in development, I suspect the functionality for relative *-imports was left out because it's not necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜