Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add parent directory to path?

3,806 views
Skip to first unread message

Rick Muller

unread,
Jul 2, 2002, 2:51:25 PM7/2/02
to
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

Chris Liechti

unread,
Jul 2, 2002, 3:08:31 PM7/2/02
to
Rick Muller <r...@wag.caltech.edu> wrote in
news:3D21F62D...@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 <clie...@gmx.net>

Richard P. Muller

unread,
Jul 2, 2002, 3:18:03 PM7/2/02
to

Chris,

os.path.abspath(os.curdir) works. Thanks.

Rick

--
Richard P. Muller, Ph.D.
r...@wag.caltech.edu
http://www.wag.caltech.edu/home/rpm

William Park

unread,
Jul 2, 2002, 4:00:09 PM7/2/02
to

What does this have to do with the original post of this thread? Please
start new thread for new subject.

--
William Park, Open Geometry Consulting, <openge...@yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin

0 new messages