"Joseph Turian" <[EMAIL PROTECTED]> writes: > Hi, > > What is the safest manner to extend search path for modules, minimizing > the likelihood of shooting oneself in the foot? > > The system (which includes scripts and their shared modules) may be > checked out in several different locations, but a script in a > particular checked-out version of the system should only use modules > from that checkout location. > > e.g. if the system contains a directory scripts/foo/ where all the > scripts are housed, and scripts/modules/ where all the modules are > housed, then is it correct for each script in scripts/foo/ to begin > with: > import sys, os.path > sys.path.append(os.path.join(sys.path[0], "../modules")) > > If so, is there a cleaner way of doing this than including the above > text in all scripts?
Put that text in a module that is already on the path, and then import that module. Or mabye generalize it into a function: import sys, os.path def fixpath(*new): sys.path.extend(os.path.join(sys.path[0], x) for x in new) This requires 2.4. Change it to ([os.path ... new]) for earlier versions. Of course, I note that sys.path[0] is '', so the join doesn't do anything. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list