With sincere apologies for such a basic question, and one i will  
admit that i asked once before, moons ago. But even after googling  
around a bit i don't understand what the right answer is, or if i  
once did, can't recall it now..

I have a script, let's call it foo.py

This script loads several modules from the standard library and a  
home brewed module that has a bunch code that i often reuse in it.

For example it might have:

# -- foo.py --

# -- batteries included
import random
import sys
import time

# -- homebrewed
import kp

[... code here ..]

That is fine and in this script i will call and use various things
from the random, sys, and time modules.

but my kp module also uses happens to call on certain things from the
random, time, and sys modules and so kp.py also has

import random
import sys
import time

Now so far this seems to be working fine and without error (as far as  
i can tell). However, shouldn't i only be importing random, sys and  
time once? and if so, where? in foo.py or kp.py?

It was explained to me that it is fine to import random, sys and time  
in both, and that only the first import uses up memory, and  
subsequent attempts to import the same module don't really cost  
anything and just add a reference in the namespace. but isn't loading  
it in both modules confusing and bad .... additionally in this case  
which import is actually being used (or does this not even matter?)  
the one in kp.py or in foo.py?

For some reason i feel like i should understand how and why this  
works a little better in order to avoid overlap and conflict in what  
is becoming a bit more involved intermingling of modules and scripts.

or alternately you all can chime in and say "dude, get over it,  
multiple and overlapping imports are not a big deal in python, you  
are worrying about nothing,  and making a problem where there is  
none! Get on with your life." haha

best,

kevin




_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to