Add parent directory to path?

Rick Muller rpm at wag.caltech.edu
Tue Jul 2 14:51:25 EDT 2002


I often use the little hack

import sys
sys.path.append('..')

to add the parent directory to the python path. It's nice, e.g., if I 
want to keep a directory below the program directory that contains test 
scripts, but still let them easily import the parent directory's modules.

This hack worked on Unix and Windows/Cygwin, which up until recently 
were my only build targets. Now I just got a Apple OS X box, and I find 
that, despite the BSD heritage, this little hack no longer works. Is 
there a good platform-independent way of doing this? I figure that 
something like this should live in os.path, but I didn't find anything 
appropriate.

Thanks in advance for any help anyone can offer.

Rick




More information about the Python-list mailing list