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.





-----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

Reply via email to