开发者

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

开发者 https://www.devze.com 2023-03-10 15:56 出处:网络
What\'s the rationale behind not allowing * in relative imports? e.g. from ..new_tool import * or doing a relative import directly:

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

精彩评论

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