Performance between “from package import *” and “import package”

强颜欢笑 提交于 2021-01-27 03:52:32

问题


Is there any performance difference between from package import * and import package?


回答1:


No, the difference is not a question of performance. In both cases, the entire module must be parsed, and any module-level code will be executed. The only difference is in namespaces: in the first, all the names in the imported module will become names in the current module; in the second, only the package name is defined in the current module.

That said, there's very rarely a good reason to use from foo import *. Either import the module, or import specific names from it.



来源:https://stackoverflow.com/questions/15655224/performance-between-from-package-import-and-import-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!