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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.
a
,b
andc
function. The difference between the first one and the second one is in the first it is not a module here, it's a package. Using the first import you have to do Mod1.function(), in the second import you can call the function directly. – Holmes