davea at ieee.org
Mon May 11 20:30:37 EDT 2009
> <div class="moz-text-flowed" style="font-family: -moz-fixed">hellcats
>> I have Python2.5 installed on Windows XP. Whenever I double click on a
>> something.pyw file, IDLE launches and opens something.pyw in the
>> editor. I would prefer to actually *RUN* the program, not edit it. If
>> I want to edit it then I'll choose the "Edit with IDLE" context menu.
>> So I then have to press F5 to get the program to execute. Now I have
>> my program's windows along with two IDLE windows cluttering my screen
>> and task bar. WHAT IS GOING ON? I've tried changing the file
>> association to python.exe, and that works, but just ONCE (even if I
>> choose "always use the slected program to launch this kind of file").
>> IDLE may be great and all, but I fricken' don't want to see it every
>> time I just want to run a python program!!!!!
> I agree completely. Check the Python-List archives. Look for a file
> that is dated July 8, 2008 (07/08/2008) that was sent by norseman.
> It works for me.
For a Unix person, you sure act like you know Windows. But changing the
PATH environment variable affects a command typed in the shell, but does
not affect what happens when you either type the name of a python script
directly, or when you double-click on such a file. That's controlled by
file associations. (PATH isn't the answer in Unix either, most shells
use the shebang at the beginning of the script.)
File associations can be controlled in a number of ways. OPEN-WITH is
one way. REGEDIT is another. In fact, any program can modify these
settings, including your own scripts. Something is changing things back
on you. But once you're having the problem of things reverting
"automatically," a command line tool is sometimes the easiest.
Two built-in commands (they're inside the cmd.exe shell) can help.
They're ASSOC and FTYPE
Since the extension you're bothered by is .pyw, try the following:
C:> assoc .pyw
C:> ftype Python.NoConFile
Python.NoConFile="C:\ProgFiles\Python26\pythonw.exe" "%1" %*
Type them once and copy/paste results somewhere.
Then fix the problem, and look again. Check that they work by
double-clicking a xxx.pyw file in Explorer.
Now, run other things, especially IDLE, and recheck these two commands
to see if something changed. If it did, then blame whatever program you
My guess is that it changed when some Python installation was done. And
some programs have a habit of continually resetting their own
associations. Sometimes this is configurable, sometimes you just have
to stop using the brain-dead program.
Notes: your path is unlikely to be the same as mine, so replace the
C:\ProgFiles... string as appropriate to your preferred Python version
location. Note you want Pythonw.exe, or you'll wind up with an extra
shell window. You can do the same thing for the .py extension, which
should wind up running python.exe. And you can make a simple two-line
batch file to set these (assoc/ftype). If you had several such batch
files you could change the default python very easily. Unlike
environment variables, these associations are global, across all users,
across all applications. So changes made in one shell affect any other
shells, as well as the Explorer windows.
Final note: once you've got these right, you can run a script in the
obvious way (like Unix).
myprogram.py parm1 parm2
will actually run python.exe myprogram.py parm1 parm2
And if you add a .PY and .PYW to PATHEXT environment variable, you can
myprogram parm1 parm2
without any extension on the script name. This should normally be done
in the Control Panel->Environment vars so it'll work in multiple DOS
boxes, same as all environment variable changes.
More information about the Python-list