[英]Difference between memory usage when importing modules
I'd like to know whats is the difference between the memory usage when importing modules in these ways: 我想知道以下列方式导入模块时内存使用之间的区别是什么:
import Mod1
from Mod1 import *
from Mod1 import a,b,c
Mainly between the first two. 主要在前两个之间。
The first uses the least memory since it only creates a single name in the module scope. 第一个使用最少的内存,因为它仅在模块范围内创建一个名称。
The second uses the most (assuming Mod1
contains more than just a
, b
, and c
either explicitly or in __all__
) since all names are recreated. 第二个使用最多(假设Mod1
显式地或在__all__
包含的不仅仅是a
, b
和c
),因为所有名称都已重新创建。
In all three cases the entire module is imported and executed, so if you're looking for large memory savings this is not what you want to optimize. 在这三种情况下,整个模块都是导入并执行的,因此,如果您要节省大量内存,那不是您要优化的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.