importing out of cwd

Neil Macneale macneale at cats.ucsc.edu
Sat Sep 9 23:10:11 CEST 2000


What is the syntax to import something that is not in the current working
directory.  Specifically I want to import something from one directory up.

This works from the command line:

>>>import os
>>>os.chdir("..")
>>>import what_I_want_to_import
>>>os.chdir("DIRECTORY_I_WANT_TO_BE_IN")

The reason I don't like this is that I want to put it all in a script that
won't necessarily be in the correct working directory.  the code:

>>> import ../what_I_want_to_import

does not seem to work. There must be some way to do this (without adding
the top directory to my puthon path) that I have missed.

Thanks,  Neil Macneale





More information about the Python-list mailing list