RE: A switch somewhere, or bug? CORRECTION
"Em" <[email protected]> Sun, 7 Dec 2025 05:03:56 -0500
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
Footnote: Fifteen plus Fifteen is thirty. Sixteen and Sixteen is thirty too. -----Original Message----- From: MRAB <[email protected]> Sent: Saturday, December 6, 2025 9:59 PM To: [email protected] Subject: Re: A switch somewhere, or bug? CORRECTION On 07/12/2025 00:54, Thomas Passin wrote: > On 12/6/2025 6:49 PM, Em wrote: >> For at least the last 10 years. I have been using double click on the >> filename (or by shortcut) to use the program. It tracks the Insulin >> injections for me and creates/updates several text files. I have been >> using IDLE for editing on WIN10 computers. No issues.... >> >> When I copied the file to the new WIN11 computer and double-click on >> the filename, it fails without warning or explanation. In WIN11, I >> can open the file with IDLE and use F5 to run it successfully. >> >> I was told to try "Open with Python" and it fails on both the WIN10 >> and >> WIN11 computers. I do not see the option for this program to Run as >> Administrator on either computer. I have seen/used Run as >> Administrator elsewhere on the WIN10 computer. >> >> I created a .py program with the lines of code: >> >> pause = input("Start") >> Starter = open("HLY-LOG5.txt","w") >> pause = input("End") >> >> and can follow all six of the techniques to run as mentioned above. >> Three situations, the program runs, and three have the program fail. >> Exactly the >> same results as with my medical program. >> >> Has my short, three line, program worked on your system? > > You should have sent this message to the group, not just me. Yes, your > program created the file but not when I double-clicked on the file > name. As I explained in my last post, that's because in Windows 11 > when double-clicking, the working directory is the system's Windows > directory, not the one your program is in. In Win 11, you don't have > access to it as an ordinary user. Anyway even if you did, you don't > want to write your file there. > > There's a simple solution if you want to be able to launch by double > clicking the file. Actually, there are at least four ways to go. > > 1. Run your program using a batch file. in the batch file, cd to your > target directory before launching your program. The batch file needs > to be somewhere on your path, or alternatively you can put a shortcut > to it on your desktop. > > If you don't know how to do any of those things, ask for help. > > 2. Make your Python program change directories to the target directory > before writing the file. I think someone already posted a code snippet > showing how to do that. If not, and you don't know how, ask for help. > > 3. Hard-code the full path to your target file. Then it won't matter > what working directory is in effect. > > 4.Create a shortcut for your .py file on the desktop. Then open the > Properties dialog for the shortcut. In the "Shortcut" tab you can put > the desired working directory. Now when you double click the > shortcut, it will open in the right directory. > So, is this a change from WIN10? and is IDLE not affected by this change? And what use is the following from MRAB: I always find a script's location with `__file__`. If "HLY-LOG5.txt" is in the same folder as the script, then its path is given by: from os.path import dirname, join log_path = join(dirname(__file__), "HLY-LOG5.txt") -- https://mail.python.org/mailman3//lists/python-list.python.org