[Tutor] HOWTO exit

alan.gauld@bt.com alan.gauld@bt.com
Mon, 23 Jul 2001 17:47:11 +0100


> I think I'm a little confused about importing modules.  

Probably :-)

> tempted to use
> "from sys import exit" and "exit()."
> 
> I'm assuming the entire module uses more memory than just the 
> one function

In fact when you import the "entire module" you are just 
making the name (sys in this case) available.
Its roughly equivalent to adding one element to 
a dictionary. If you do "from ... exit" you import
exit instead of sys but again its only one entry in 
the dictionary. 

The difference comes when you want to use something 
else in sys (say argv) then you have the choce of 
importing 2 names(exit and argv) or one name (sys) 
and using it to reference the others...

Because of the dangers of overwriting a local name 
with an imported one most pythomnistas seem to 
prefer to avoid "from..." except for well defined 
cases such as tkinter.

Alan G