[Pythonmac-SIG] Re: cwd and PythonLauncher problem -- a bit more info

Bob Ippolito bob at redivi.com
Fri Oct 1 20:03:58 CEST 2004


On Oct 1, 2004, at 1:51 PM, Chris Barker wrote:

> Bob Ippolito wrote:
>
>> GUI apps in OS X always have a current directory of /
>
> really? UGG!

Well if you think about it, it makes sense... where else would it be?  
The Resources folder of the application?  The folder the application is 
in?  It's ambiguous and really depends on what your application does.

> > (not sure why you ever saw it
>> have a path of the user directory, maybe PythonLauncher does that on 
>> purpose?).  It would make sense for PythonLauncher to behave 
>> otherwise though.
>> In the meantime, you could do:
>> import os
>> os.chdir(os.path.dirname(__file__))
>> which will change to the directory that your script is in.
>
> Is there a reliable way to change it to the user's home directory? can 
> you count on this?:
>
> import os
> os.chdir(os.getenv("HOME"))
>
> this works from a shell, but will HOME be defined in a GUI app?

That should work fine.

-bob


More information about the Pythonmac-SIG mailing list