[Tutor] about importing a module

Kent Johnson kent37 at tds.net
Thu Jul 19 21:06:47 CEST 2007

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__


> 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 at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list