Correctness: sys.path.append("..")

Jeremy Bowers clp at jerf.org
Tue Jan 8 21:44:00 EST 2002


Mark McEahern <marklists at mceahern.com> wrote:
> Jeremy Bowers
>> I've taken to sticking this on top of my files in the subdirectories:
>>
>> import sys
>> if ".." not in sys.path:
>>       sys.path.append("..")
> 
> Suppose you have the following structure:
> 
>        /myproj/biz/customer.py
>        /myproj/presentation/layout.py
>        /myproj/data/tabular.py
> 
> and you have a module in myproj that needs to use modules in biz,
> presentation, and data:

I have modules in biz that want, nay, need to use modules in presentation.

"Ideally", I'd have some sort of syntax like this:

import ../presentation.layout

or

import __parent__.presentation.layout

or something like that.

(I'm aware neither is perfect, and there are big problems with the first 
syntax. I'm just giving examples.)

Mucking with sys.path had the virtue of working. A sibling to your post
gave me a solution that will work on the targeted platforms adequately
for my purposes.




More information about the Python-list mailing list