[Pythonmac-SIG] Re: newbie file path question

Dean Draayer draayer@surfglobal.net
Tue, 17 Jul 2001 02:11:27 -0400


On Sun, 15 Jul 2001 18:16:37 -0400, Richard Gordon wrote:

> Aside from Just's suggestion that you edit your preferences to 
> include the desired path, you could temporarily append it to 
> sys.path as follows:
> 
> import sys
> sys.path.append('HD:folder1:folder2:folder3')
> import test1


Or let the IDE do it for you with a GetDirectory call.  I like to put 
the following scripts in the Python IDE Scripts folder (set via menu 
Python > Preferences > Set Scripts folder...):

#----------
# Script: "Add Folder to Search Path.py"

import macfs
import sys

(f,OK) = macfs.GetDirectory("Select a folder to add to sys.path:")
if OK:
    f = f.as_pathname()
    sys.path.insert(0,f)    # put at front of the search path
#----------

#----------
# Script: "Show Search Path.py"

from sys import path
print "sys.path:"
for p in path:
    print "\t%s" % p
#----------

I like to put ':' as the first item in my global IDE/Interpreter 
search path.  When a script is saved as an applet or application, this 
will refer to the folder containing it.  But when editing the script 
in Python IDE, ':' refers to the IDE's parent folder.  (I don't like 
to litter the global IDE/Interpreter paths with my individual project 
folders.)  "Add Folder to Search Path.py" provides a quick-and-dirty 
way to get the applet-to-be's parent in the search path while working 
on it in the IDE.

Dean Draayer