[英]Python: Import all modules from package
There is a package. In the package's __init__.py
there is __all__
defined which contains name of every module in package. If I then use有一个 package。在包的
__init__.py
中有__all__
定义,其中包含 package 中每个模块的名称。如果我然后使用
from package import *
will it import every module of that package so I can reference them by name?它会导入 package 的每个模块以便我可以按名称引用它们吗?
Is it possible in Python to import every package's module with from x import *
statement?是否可以在 Python 中使用
from x import *
语句导入每个包的模块?
Yes.是的。 But because of "namespace pollution" (not knowing which imported module you actually use because perhaps several of them have the same name), it is not recommended.
但由于“命名空间污染”(不知道你实际使用的是哪个导入模块,因为可能其中有几个具有相同的名称),不推荐使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.