Set Python Path for Idle Mac 10.5

Ned Deily nad at acm.org
Tue Jul 20 22:48:19 EDT 2010


In article 
<AANLkTimrUhTiCD07T-sHaCgp3Rgd3o4sEj8FsK7Af8Vu at mail.gmail.com>,
 neoethical <neoethical at gmail.com> wrote:
> New to programming and after doing some research I've chosed to work with
> Python. One thing that's bothering me is that I would like to set up a
> specific folder in my Documents folder to hold my modules. How do I go about
> doing this? I've found the way to change it for each IDLE session but I'd
> like to make it check the folder automatically. I've done a bunch of
> searches and have come up with nothing helpful.

On OS X, depending on which version of Python you are using, there are 
usually two ways to start IDLE: either by launching IDLE.app (often 
found in /Applications/Python x.y or /Applications/MacPython x.y) or by 
invoking IDLE from the command line (generally something like 
/usr/local/bin/idlex.y).  When started from a terminal command line, 
IDLE uses the current working directory ("folder") as the default for 
opening and saving files from the shell window.  When you "launch" 
IDLE.app (by double-clicking on its icon, for example), it always uses 
Documents as the default working directory.

Unfortunately, AFAIK, there is no built-in way to specify a different 
default for the shell window, which is a bit annoying.  The simplest way 
to work around it, I think, would be to always start IDLE from the 
command line after changing to the desired default directory.  So, from 
a terminal session (in Terminal.app or equivalent), something like this 
for, say, python3.1 installed from python.org:

    cd /path/to/default/directory
    /usr/local/bin/idle3.1

The equivalent could be turned into a shell function or alias or an 
AppleScript app or Automator action.

>From the command line, you can also give IDLE a list of one or more 
files to open, each in its own file window.  When the focus is on a file 
window, file command such as open and save default to the directory of 
the opened file (this is also true in IDLE.app).  So you could have 
something like this:

    cd /path/to/project/directory
    /usr/local/bin/idle3.1 my_mod_1.py  my_mod_2.py ...

or, if you want to edit all of the python modules in a directory:

    cd /path/to/project/directory
    /usr/local/bin/idle3.1 *.py

You can achieve a similar effect (except for the shell window) in the 
Finder by dragging the files to the IDLE.app icon (in a Finder window or 
on the dock).  Double-clicking on the .py files themselves can be made 
to work but it's a bit of a crap shoot which version of IDLE or other 
app might actually be launched;  it's best to avoid depending on that 
mechanism.

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list