When I double-click the file my_app.py, I want to open it with python.exe. When I double-click any other .py file, I want to open it with a text editor. How do I set this up in Windows 7 and 8?

Here is what I tried:

  1. Right-click my_app.py

  2. Click "Properties"

  3. In the "General" tab, under "Opens with", click "Change"

  4. There is a checkbox labeled "Always use the selected program to open this kind of file". Perfect, I just need to uncheck this box. Unfortunately, the box is grayed out and checked, I cannot uncheck it.

How do I uncheck this box? Why is it grayed out?

Thank you.

| improve this question | | | | |

An indirect solution will be to associate .py with a batch file (or autohotkey?). The batch file should check the file name and invoke python if it is my_app.py and text editor if it is not.

Otherwise I don't think you can open one file with a certain extension with one application and the remaining files with the same extension with another application, directly in Windows. Windows sees the extension and opens the associated file. The option "Always use the selected program to open this kind of file" is just to say if you want windows to automatically open the file with this application or ask every time you double click.

| improve this answer | | | | |

I believe that you're treating the "Open with..." dialogue as a file-specific property that can apply differently to two files of the same type. However, in Windows you can only configure default "Open with" behaviour on a per-extension basis. The "Open with..." dialogue will make changes to how Windows treats all .py files.

To accomplish what you need, you can follow these steps (written for Windows 7):

  1. Go to "Opens with..." again and set your text editor as the default handler
  2. In the folder containing my_app.py, right click a blank area and select New -> Shortcut
  3. Click "Browse..." and select your python.exe file, and click OK
  4. In the text box under "Type the location of the item:", add a space and put type the path to my_app.py to look like this, including the quotes: C:\Python33\python.exe "F:\My App\my_app.py"
  5. Click "Next" and give it a name like "Run my_app" and click "Finish".

This shortcut should explicitly tell Windows to run Python's interpreter with my_app.py as the argument, thus allowing you to implement this file-specific behaviour.

If you want to modify this shortcut or a duplicate of it to open another .py file, you could go to Properties and in the "Shortcut" tab change the "Target:" box to point at the other .py file.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.