What exactly does “import *” import?

后端 未结 6 1297
梦如初夏
梦如初夏 2020-11-22 16:25

In Python, what exactly does import * import? Does it import __init__.py found in the containing folder?

For example, is it necessary to de

6条回答
  •  面向向阳花
    2020-11-22 17:03

    If project.model is a package, the module referred to by import project.model is from .../project/model/__init__.py. from project.model import * dumps everything from __init__.py's namespace into yours. It does not automatically do anything with the other modules in model. The preferred style is for __init__.py not to contain anything.

    Never ever ever ever ever use import *. It makes your code unreadable and unmaintainable.

提交回复
热议问题