how to prevent python import from looking into the current directory

Benjamin Peterson benjamin at python.org
Fri Mar 6 16:40:19 EST 2009


TP <Tribulations <at> Paralleles.invalid> writes:

> 
> Hi everybody,
> 
> I would like to prevent the loading of modules in the current directory.
> For example, if I have a personal module in the current directory
> named "os", when I do "import os", I would like Python to import os
> standard module, not my personal module of the current directory.
> Is this possible?

While the solutions given by others in this thread will work, I think it is best
policy to not name your own modules after stdlib ones. When I see "os"
referenced in code, I assume it is the stdlib one, and don't want to be confused
by the presence of your own module.





More information about the Python-list mailing list