On 2/27/2026 9:49 AM, Em 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?

Yes. The way in which Windows determines and runs the executable program (like python) when a file is invoked by using its name has changed from what we all got used to. And the way it's launched when the file's icon is clicked in Windows Explorer has been changed too. The change to how the default launch program is chosen has been phased in starting with later versions of Windows 10. Windows 11 changed the launching method too.

Here's a tiny program you can use to see what's happening:

import os
print('Current Directory:', os.getcwd())
input()

Because of the input() statement you will need to press ENTER to close the window, but its presence forces the window to remain open so you can see the printout.

When I run this from a console by typing the file's name (call it cwd.py) it prints the current directory of that console. That's what one expects.

When I run it from by clicking the program's file name in Windows Explorer, it prints

C:\WINDOWS\system32

So you are not imagining things, and you will have to either launch your programs differently, or rewrite them to use the correct path, as has already been suggested.
--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to