[CentralOH] Idle MacPython 2.6.4 / sys.Path

Mark Erbaugh mark at microenh.com
Wed Dec 30 20:17:48 CET 2009

On Dec 30, 2009, at 1:10 PM, Mark Erbaugh wrote:

> I did a little more digging, but still don't know enough about the Mac launch process.  Here's what I have found.
> If you view the contents of the IDLE Package (Mac Package, not a Python Package), in Contents/MacOS is a python script IDLE.py that apparently participates in the process. It runs the python script idlemain.py which is in the Contents/Resources folder.  I've been able to walk through the process and see where idlemain.py is setting the current working directory (to my Documents folder).  There are some notes in idlemain.py about what it is doing.
> What I haven't been able to find is how the .py file(s) that I want to open are passed to idle. They aren't in sys.argv passed to either IDLE.py or idlemain.py. They don't appear to be in environment variables.  I'm thinking that if I can find the .py file that I want to start with, I could modify idlemain.py to set the current working directory to it's folder. Perhaps that's the rub, the files launched can't be found and why the launcher doesn't already do this.

Well, I think I've figured out the root of the problem.  The solution will be trickier <g>.

It looks like what Idle is doing on the Mac is binding a handler for an open file event. From the comments in the code (idlelib.macosxSupport), it looks like the Mac launcher uses this file open event to pass the files to be opened to Idle.

I think the easiest solution would be to modify the code in macosxSupport to change the working directory to the directory of the first file it opens and to add that directory to sys.path. Of course, that requires modifying a "library" module, so my Idle won't be "standard". 


More information about the CentralOH mailing list