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

Jeremy Bowers clp at jerf.org
Tue Jan 8 17:01:04 EST 2002


I'm writing some Python apps[1] and I don't like having all the files in
one directory. So I setup sub-directories. Some files in the subdirectories
need to import files from the parent or sibling directories.
 
I've taken to sticking this on top of my files in the subdirectories:

import sys
if ".." not in sys.path:
	sys.path.append("..")

(proceed to import modules)

I know it works on Windows and Linux, for the last few versions of Python.
Is there any thing wrong with this? It makes me vaguely nervous.

(The programs are targeting computers, not handhelds or embedded platforms,
so I'm not worried about things that may not have a filesystem, for instance.)



[1] Which contains about as much information in a post to this newsgroup
    as "A guy walks into a bar..."





More information about the Python-list mailing list