Changes in import statement python3

前端 未结 4 1900
执笔经年
执笔经年 2020-11-22 04:54

I don\'t understand the following from pep-0404

In Python 3, implicit relative imports within packages are no longer available - only absolute impor

4条回答
  •  佛祖请我去吃肉
    2020-11-22 05:37

    For relative imports see the documentation. A relative import is when you import from a module relative to that module's location, instead of absolutely from sys.path.

    As for import *, Python 2 allowed star imports within functions, for instance:

    >>> def f():
    ...     from math import *
    ...     print sqrt
    

    A warning is issued for this in Python 2 (at least recent versions). In Python 3 it is no longer allowed and you can only do star imports at the top level of a module (not inside functions or classes).

提交回复
热议问题