module imports and memory usage

Brad Tilley bradtilley at
Tue Nov 30 22:46:43 CET 2004

Brad Tilley wrote:
> When memory usage is a concern, is it better to do:
> from X import Y
> or
> import X
> Also, is there a way to load and unload modules as they are needed. I 
> have some scripts that sleep for extended periods during a while loop 
> and I need to be as memory friendly as possible. I can post a detailed 
> script that currently uses ~ 10MB of memory if anyone is interested.
> Thanks,
> Brad

I discovered that when I wrap my code up in a function def and call it 
that it uses around 4.6 MB of RAM all the time... even while sleeping. 
However, when I don't put it in a function def it uses around 2.6MB of 
data when it executes and only 100KB while sleeping. Why is this?

More information about the Python-list mailing list