This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author busfault
Recipients busfault, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2016-04-27.17:17:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1461777447.66.0.837896919007.issue26866@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-04-27 17:17:27busfaultsetrecipients: + busfault, paul.moore, tim.golden, zach.ware, eryksun, steve.dower
2016-04-27 17:17:27busfaultsetmessageid: <1461777447.66.0.837896919007.issue26866@psf.upfronthosting.co.za>
2016-04-27 17:17:27busfaultlinkissue26866 messages
2016-04-27 17:17:27busfaultcreate