[Tutor] about importing a module

Tiger12506 keridee at jayco.net
Tue Jul 24 01:35:01 CEST 2007


>> If the module has been imported before your code is run, it will be the 
>> library module (very important if working in IDLE which importants many 
>> modules, for example).

> So... how does IDLE go about importanting a module? ;)

It's not *how* IDLE imports the module, but that fact that IDLE imports the 
module before his script would be executed. For example:

### sys.py ###
path = "Hello"
############

### test.py ###
import sys

print sys.path
############

Save sys.py and test.py in the same directory. Run test.py from the command 
line. Then open test.py in IDLE and run it in IDLE. You should get two 
different results because IDLE imports sys as part of it's own code and 
python does not re-import modules. However, when you run test.py from the 
command line, sys has not been previously imported and our own sys.py is 
imported.

Hope this explains my reasoning.
JS 



More information about the Tutor mailing list