RE: Win 10 > Win 11 path error?
"Em" <[email protected]> Fri, 27 Feb 2026 17:34:46 -0500
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
-----Original Message----- From: Dan Sommers <[email protected]> Sent: Friday, February 27, 2026 11:54 AM To: MRAB <[email protected]>; Em <[email protected]> Cc: [email protected] Subject: Re: Win 10 > Win 11 path error? On 2026-02-26 at 19:35:13 +0000, Regarding "Re: Win 10 > Win 11 path error?," MRAB <[email protected]> wrote: > On 26/02/2026 17:53, Em wrote: > > OutExcelFile = open("_EXCEL-FILE3az.txt","w") > > > > The line works in Win 10. > > In Win 11, if I press F5 it works but if I double click on the program filename, it fails immediately. > > No error reported. > > > > I believe the problem with the path needing to be different between Win10 and Win11. > > Can you tell me what the path should be if that is the problem? > > > > Python: 3.14.1 > > > "_EXCEL-FILE3az.txt" is a relative path. It looks in the current > working directory, wherever that happens to be. It's better to work > with full filepaths. The path of the script is given by `__file__`, > and its directory by `os.path.dirname(__file__)`, so: > this_directory = > os.path.dirname(__file__) > > If "_EXCEL-FILE3az.txt" is in the same directory as the script, its full path will be given by: > > data_path =os.path.join(this_directory, "_EXCEL-FILE3az.txt") > > You can then write: > > OutExcelFile = open(data_path,"w") > > -- > https://mail.python.org/mailman3//lists/python-list.python.o rg On 2026-02-27 at 09:49:11 -0500, Regarding "Another issue between Win10 and Win 11 using python," Em <[email protected]> wrote: > > The statement is: ThisPath = os.getcwd() > > For 10 years in Win 10 the line gave me the present path both when I used F5 in an editor, and when I ran the program by a double-click on the name of the program in the folder. > > I now want to run the program in Win 11. > As in Win 10, F5 from an editor, it gives me the present path but when I double-click on the program in the folder, it gives me some system path on the C drive. > > This is now the second line of code that fails like this. > Can someone explain why. > Can you suggest a line of code to get the present path for this that is allowed by Win 11? I think that's what MRAB already did: this_directory = os.path.dirname(__file__) data_path = os.path.join(this_directory, "_EXCEL-FILE3az.txt") OutExcelFile = open(data_path,"w") I don't understand that line of code.... -- https://mail.python.org/mailman3//lists/python-list.python.o rg -- https://mail.python.org/mailman3//lists/python-list.python.org