Ok, using "Open with Python" , the program fails on both computers.
Still, double-click the filename on the WIN10 computer and the program
works.
While, double-click the filename on the WIN11 computer and the program
fails.

-----Original Message-----
From: Thomas Passin <[email protected]> 
Sent: Friday, December 5, 2025 4:34 PM
To: [email protected]
Subject: Re: A switch somewhere, or bug? CORRECTION

On 12/5/2025 3:03 PM, Em wrote:
> Alright, Alright, Alright...
> Alright.
> 
> These responses push much more sophisticated explanations than the 
> question asked.  This involves only one line of code that creates an empty
text file.
> No other code is involved or needed.
> 
> Before responding, please run this test:
> 
> Create a .py file that contains the line:
> Starter = open("HLYlog.txt", "w")
> 
> Copy that file onto a folder in a WIN10 computer which uses Python 
> 3.13 and copy it again onto a folder in a WIN11 computer that runs 
> Python 3.14.1
> 
> Double-click the filename in the folder on the
> WIN10 computer. It executes the program and the text file is created.
> 
> Double-click the filename in the folder on the
> WIN11 computer and it fails, no text file is created.
> No error statement is generated.
> 
> The strange thing here is that, on the WIN11 computer, I right-click 
> and choose "Edit with IDLE" option.  The file code is shown and I 
> press F5.  The program runs properly and the text file is created.  Of 
> course, IDLE does not show an error report on a working program.
> 
> The medical program that I wrote, and have used for 20 years, works on 
> the WIN10 computer. I now want to copy it to the WIN11 computer and it 
> consistently fails on this line.
> 
> The change from WIN10 Python 3.13 to WIN11 Python 3.14 is the only 
> difference I can see.

You have been mixing up two things, and it's confusing to people who want to
help:

1. Running a .py file by double-clicking the .py file name in Windows
Explorer; 2. Whether or not your program works using this Python install,
when run from the command line in a Console.

Kindly try to run the program with Python from the command line. By that I
mean some variation of "py your_program.py". Of course, you first need to CD
to its directory; otherwise you have to include the full path. See if it
creates the file it's supposed to. If it does, delete the created file, and
try to run the program from the console just using the file's name,
*without* prefixing it with "py", "python" or whatever you used to run it
when it succeeded. You should see a new console flash up for a moment then
close and vanish.  See if the file was created.

Running by typing the .py file name by itself should will launch it the same
way it would be launched when you double click on the file name.

If the file was created when you ran your file with the python executable,
that verifies the program ran and functions.  Since it works in IDLE, that
should succeed.  Then if it fails when typing just the bare program name,
that would show that the file association for .py files isn't set up.
Unfortunately, the new console doesn't stay visible long enough to see any
error messages and you have to work around that fact to make sure of what is
going on.

Another way to check is to right-click on your .py file in Windows Explorer,
and go down to the "Open With" menu item. The first name in that list should
be some variation of "Python (Default)". If that's not the case, you need to
set up the file association using the Settings/Default apps settings page,
as I mentioned in an earlier post.

I suspect that the file association hasn't been set up.  That was the case
on my Windows 11 computer too.

> 
> 
> 
> 
> -----Original Message-----
> From: Michael Torrie via Python-list <[email protected]>
> Sent: Friday, December 5, 2025 1:18 PM
> To: [email protected]
> Subject: Re: A switch somewhere, or bug? CORRECTION
> 
> On 12/4/25 10:47 PM, Em wrote:
>>> Starter = open("HLYlog.txt", "w")
>>>
>>> Thoughts appreciated.
>>
>> -That's a relative path. Are you sure that the current working 
>> directory is what -you expect? It's generally better to work with 
>> absolute paths.
>>
>> Relative or not, I can't see how that could possibly make any difference.
> 
> You don't? Why? The key word is "working directory."  How do you know 
> what the working directory is? If you start a program using a shortcut 
> link, the link can specify any arbitrary directory.  If you start it 
> from idle, idle sets the working directory. If you double click the py 
> file, the pylauncher sets the working directory. All could be and in 
> fact are different.  If you always want it to open that file in the 
> same directory as the script, then you can use code such as the following:
> 
> import os
> 
> # Get the absolute path of the current python file we're running 
> current_file_path = os.path.abspath(__file__)
> 
> # Get the directory of the current file current_directory = 
> os.path.dirname(current_file_path)
> 
> print(f"The directory of the current file is: {current_directory}")
> 
> (disclaimer, suggested by  AI, verified by me to be correct).
> --
> https://mail.python.org/mailman3//lists/python-list.python.org
> 

--
https://mail.python.org/mailman3//lists/python-list.python.org

-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to