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