How to import Python files in the other directories?

Ben Finney bignose+hates-spam at
Fri Mar 6 07:55:38 CET 2009

Muddy Coder <cosmo_general at> writes:

> If I have a python file in the current directory, I can
> simply import it in the way below:
> import foo

Because the current directory, '.', is in the import search path.

> when a project keeps grow, more and more Python files are created,
> and they are also needed to put into different directories. Then, a
> problem comes: how to import the Python files residing in the other
> directories? Somebody helps me out? Thanks!

Modify the import search path, which is a list named ‘sys.path’
<URL:>, to have an
entry for each path you want to be searched when importing a module.

 \       “The right to use [strong cryptography] is the right to speak |
  `\                                             Navajo.” —Eben Moglen |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list