How to import from a file which is not in the current directory?

Philip Semanchuk philip at semanchuk.com
Thu Oct 23 00:01:06 CEST 2008


On Oct 22, 2008, at 5:38 PM, Kurda Yon wrote:

> Hi,
>
> I would like to import a function from a file which is located not in
> the same directory as the main program (from which the function needed
> to be imported).
>
> Could anybody pleas tell me how to do that?

Python will search for module files in a number of places:
http://docs.python.org/tutorial/modules.html#the-module-search-path

sys.path will give you a list of all the places that will look for  
modules.









More information about the Python-list mailing list