Multiple versions of python

Scott David Daniels Scott.Daniels at Acm.Org
Wed Jul 22 16:06:45 CEST 2009


CCW wrote:
> On 21 July, 15:19, Dave Angel <da... at dejaviewphoto.com> wrote:
>> The other thing you may want to do in a batch file is to change the file
>> associations so that you can run the .py file directly, without typing
>> "python" or "pythonw" in front of it.
>>
>> The relevant Windows commands are:     assoc and ftype      And on a
>> related note, you may want to edit the PATHEXT environment variable, to
>> add .PY and .PYW
> 
> Thanks for this - this way made a bit more sense to me.  I've now got
> C:\commands with the 4 .bat files in, and C:\commands in my path.  It
> all seems to work :) I think I've missed the point of the @ though -
> it doesn't seem to make any difference..
> 
> I'm also a bit confused with the associations - since I've got python
> 2.6 and 3.1, surely the command I type (python26 or python31) is the
> only way to force a script to be run using a specific interpreter at
> runtime without having to change the .bat file every time I want to
> run a script using 3.1 instead of 2.6?

OK, for me currently:

C:\> assoc .py
.py=Python.File

C:\> assoc .pyw
.pyw=Python.NoConFile

C:\> ftype Python.File
Python.File="C:\Python31\python.exe" "%1" %*

C:\> ftype Python.NoConFile
Python.NoConFile="C:\Python31\pythonw.exe" "%1" %*

C:\> ftype Python.File
Python.File="C:\Python31\python.exe" "%1" %*

Now imagine instead that you've added:

C:\> ftype Python31.File="C:\Python31\python.exe" "%1" %*
C:\> ftype Python31.NoConFile="C:\Python31\pythonw.exe" "%1" %*
C:\> ftype Python26.File="C:\Python26\python.exe" "%1" %*
C:\> ftype Python26.NoConFile="C:\Python26\pythonw.exe" "%1" %*

Then you can do the following:
C:\> assoc .py=Python26.File
C:\> fumble.py
C:\> assoc .py=Python31.File
C:\> fumble.py

That is the basic idea, but at the moment, I don't see a simple demo
working for me.  SO, if you want to pursue this, you can probably get it
to work.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list