Re: [Tutor] about importing a module

2007-07-23 Thread Luke Paireepinart
Tiger12506 wrote:
>>> 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:
>   
Actually I was just teasing you about saying 'IDLE, which _importants_ 
many modules' instead of 'imports.'
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] about importing a module

2007-07-23 Thread Tiger12506
>> 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 

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


Re: [Tutor] about importing a module

2007-07-19 Thread shawn bright

change the name of the module, simple.
thanks
shawn

On 7/19/07, Tiger12506 <[EMAIL PROTECTED]> wrote:


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). But if it has not been imported before, the module
in
the current directory is imported first. You can check if a module has
been
imported previously by checking if in sys.modules.

JS

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

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


Re: [Tutor] about importing a module

2007-07-19 Thread Tiger12506
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). But if it has not been imported before, the module in 
the current directory is imported first. You can check if a module has been 
imported previously by checking if in sys.modules.

JS 

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


Re: [Tutor] about importing a module

2007-07-19 Thread Tiger12506
I'm pretty sure that the one in the current directory gets imported first. 
However, it is much simpler to just change the name of the module in the 
current directory.

JS

> hello there,
>
> if i have a module that is in the same directory as the file that imports
> it,
> but that module has the same name as a module in my python path, which one
> gets imported ?
>
> i ask because i want to do some work on the module, but dont want to mess
> with my stable
> one in site-packages.
> so i want to import it from the local directory only.
>
> thanks
>
> shawn

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


Re: [Tutor] about importing a module

2007-07-19 Thread Kent Johnson
shawn bright wrote:
> hello there,
> 
> if i have a module that is in the same directory as the file that 
> imports it,
> but that module has the same name as a module in my python path, which one
> gets imported ?

The local one. sys.path has the list of directories that are searched 
for imports, in the order they are searched. The local directory is first.

You can look at the __file__ attribute of a module to see where it comes 
from, e.g.
import mymodule
print mymodule.__file__

Kent

> 
> i ask because i want to do some work on the module, but dont want to 
> mess with my stable
> one in site-packages.
> so i want to import it from the local directory only.
> 
> thanks
> 
> shawn
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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