Alan Gauld wrote on 25 November 2011 at 21:11:-
> This is one of the annoying ambiguities of Windows.
> The way it finds the executable for  executables(exe, bat cmd etc) is 
> different to how it finds the executable for associations.
>
> In the former case it uses PATH, in the latter it relies on the file 
> association set in the file properties.
>
> When you install a new Python it  tends to set itself as
> the default interpreter for .py files.

You can use the DOS commands to manipulate file associations on Windows
so that you can run two or more versions of Python on the same computer.
The DOS commands are ASSOC and FTYPE.

First you need to use ASSOC to discover the file type for .py, .pyw and
.pyc files. To use ASSOC type ASSOC followed by the extension you are
interested in. For example, find the file type for .py files, type:-

    assoc .py

Typical results from ASSOC will be:-

    .py = Python.File
    .pyw = Python.NoConFile
    .pyc = Python.CompiledFile

Next, use FTYPE to discover the 'open' commands associated with each of
these file types. To use FTYPE type FTYPE followed by the file type as
given by the ASSOC command. For example:-

    ftype Python.File

Typical results from FTYPE will be something like this:-
    
    Python.File="C:\Python27\python.exe" "%1" %*
    Python.NoConFile="C:\Python27\pythonw.exe" "%1" %*
    Python.CompiledFile="C:\Python27\python.exe" "%1" %*

What we can do now is create our own set of file types, one for Python 2.7
and one for Python 3.2. This is done using the FTYPE command (of course,
your paths may be different to the ones shown):-
    
    ftype Python32.File="C:\Python3\python.exe" "%1" %*
    ftype Python32.NoConFile="C:\Python3\pythonw.exe" "%1" %*
    ftype Python32.CompiledFile="C:\Python3\python.exe" "%1" %*
    ftype Python27.File="C:\Python27\python.exe" "%1" %*
    ftype Python27.NoConFile="C:\Python27\pythonw.exe" "%1" %*
    ftype Python27.CompiledFile="C:\Python27\python.exe" "%1" %*

That's the preparatory work completed. We can now choose which version of
Python will run when a *.py file is executed using the ASSOC command. To
select Python 3 we'd use these commands:-
    
    assoc .py = Python32.File
    assoc .pyw = Python32.NoConFile
    assoc .pyc = Python32.CompiledFile

...and to use Python 2.7 we'd use these commands:-
    
    assoc .py = Python27.File
    assoc .pyw = Python27.NoConFile
    assoc .pyc = Python27.CompiledFile

-- 
Michael

This mail was sent via Mail-SeCure System.



 
 
************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.
************************************************************************************



_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to