[Tutor] HOWTO exit
dman
dsh8290@rit.edu
Mon, 23 Jul 2001 13:48:13 -0400
On Mon, Jul 23, 2001 at 11:36:20AM -0400, fleet@teachout.org wrote:
|
| I think I'm a little confused about importing modules. If I were to do
| the below, unless I needed other 'sys' functions, I'd be tempted to use
| "from sys import exit" and "exit()."
|
| I'm assuming the entire module uses more memory than just the one function
| and I would think one should conserve memory. (Even if one doesn't have
| to - I'm from the "waste not, want not" school.)
Actually, no, the same amount of memory is used regardless. You can't
"unimport" modules. The module name might not exist in the current
module's namespace, but the module still exists in memory. I don't
think C can unload a shared library from memory (and some modules are
implemented in C) so I think that might be one reason for not
unloading modules. The other reason is the next time you import the
module it takes very little time -- the module is already in memory so
the only thing that is needed is an adding the reference in the
current namespace.
It is better to just import the module and use its members qualified
with the module name for (future) readability and it takes no
additional memory than the alternatives.
| Is there a rule of thumb regarding this issue?
Yeah, don't use from-import unless you _really_ _really_ need it.
Just think of a module as a namespace and importing it is nothing more
than making that namespace accessible.
:-)
-D