IDLEX association

eryk sun eryksun at gmail.com
Fri Nov 18 19:46:55 EST 2016


On Fri, Nov 18, 2016 at 7:09 PM, Dennis Lee Bieber
<wlfraed at ix.netcom.com> wrote:
> On Fri, 18 Nov 2016 04:46:46 -0800 (PST), Luis Marzulli
> <luchomarzulli at gmail.com> declaimed the following:
>
>>When I double click a .py file, a windows appears and immediately disappears.
>>How can I associate the .py file extension to the IDLEX EDITOR?
>
>         You really don't want to do that (I'm not familiar with "IDLEX", but
> Python's IDLE is itself a Python script, so if Python scripts were
> associated with the editor script, you'd get a recursion of the editor
> trying to open itself in the editor).

No, the file association would run IDLE[X] via pyw.exe or pythonw.exe.

If Python is installed for all users and you have the default
associations selected as you user choice in the shell (i.e.
Python.File and Python.NoConFile), then you can easily modify the .py
and .pyw file association using an elevated command prompt.
(Ironically it's harder to modify this for a per-user installation,
since cmd's assoc and ftype commands use only the system registry
hive.) For example:

Show the current association:

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

    C:\>ftype Python.File
    Python.File="C:\Windows\py.exe" "%1" %*

(Note that assoc shows the system association, but your user choice in
the shell may be different. This choice is buried in the registry
under HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice.)

Modify the "Python.File" ProgId to run IDLE 3.5 (running IDLEX is
probably similar, but I don't use it):

    C:\>ftype Python.File="C:\Windows\pyw.exe" -3.5 -m idlelib "%1" %*
    Python.File="C:\Windows\pyw.exe" -3.5 -m idlelib "%1" %*

You can easily restore the association back to the default:

    C:\>ftype Python.File="C:\Windows\py.exe" "%1" %*
    Python.File="C:\Windows\py.exe" "%1" %*

and run a test script:

    C:\>type test.py
    #!/usr/bin/python3
    import sys
    print(sys.executable)

    C:\>test.py
    C:\Program Files\Python36\python.exe

Personally I don't use an editor as the default action for .py files.
Instead I add a right-click "edit" action. For the command line, I
have an edit script that invokes this action on a file.



More information about the Python-list mailing list