norseman said:
------------------------
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.
Steve
</div>
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
..pyw=Python.NoConFile
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
just ran.
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
just run
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.