Tom Middleton added the comment:

I agree with your assessment Steve. I don't see there being a good fix to this. 
I also think it would be a bad idea to have the launcher change the current 
working directory.
Example:
c:\foo\> python d:\scripts\bar.py myfile
(where myfile is in c:\foo\)

A kludge work around in a script is something like this:
import os

if __name__ == "__main__":
    os.chdir(os.path.dirname(__file__))


I also don't think it makes sense to counteract what seems to be a Windows 
issue in python (or the launcher of which I am less familiar with). I was 
hoping it was going to be a simple registry setting or something like that 
which could be handled in the install process.


Eryk, you are correct, it was poor coding that led to the issue. I don't think 
I was clear in my initial post that I realize that opening a file and assuming 
the directory of the script is the cwd is not good practice. I was commenting 
that it is inconsistent between launching methods. I was launching a script 
that was attempting to write a log file using the logging module with a 
relative path filename. It was a gotcha because it worked fine on my desktop 
and it wasn't working when a colleague ran it from "Open with". I've since 
improved my methodology so the issue is moot for that regard.
However, it is still interesting that there is an inconsistency in Windows in 
those methods of execution. FWIW I also tested it out with perl and as I 
expected, got the same results of working directories.

Also please note that I am working in Python 2.7, there is no py launcher as 
there is in 3. I am not certain what inconsistencies may occur between calling 
py.exe v. python.exe.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26866>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to