Add parent directory to path?

Chris Liechti cliechti at gmx.net
Tue Jul 2 15:08:31 EDT 2002


Rick Muller <rpm at wag.caltech.edu> wrote in 
news:3D21F62D.9050801 at wag.caltech.edu:

> I often use the little hack
> 
> import sys
> sys.path.append('..')

i would use sys.path.append(os.path.abspath('..'))
as you might change the current dir of the app later.
 
> 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.

doo you have printed os.curdir() and os.path.abspath(os.curdir)
do thay return somthing useful? don't have OSX, but i would expect it to 
act like a unix too....


-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list