How do I add a “New” Python script option to the c

2020-06-03 02:55发布

问题:

I'm trying to add a context menu option for New -> Python Script on Windows 7. However, everything I've tried has failed.

The way that I thought it should work is below:

Add the following registry key:

[HKEY_CLASSES_ROOT\.py\ShellNew]
"FileName"="Template.py"

Null File version:

[HKEY_CLASSES_ROOT\.py\ShellNew]
"NullFile"=""

Optional registry key

[HKEY_CLASSES_ROOT\.py]
"PerceivedType"="text/plain"
@="Python Script"

Add the file to the Windows, ShellNew folder...

This does nothing, although I've done this before, and it worked with other file types. I'm unable to find anything for this anywhere, because they do everything I try for other file types.

What am I doing wrong?

EDIT: Python 2.7.8 or later has this option added during setup/installation.

Reference: MSDN Extending Shortcut Menus

回答1:

HKEY_CLASSES_ROOT\.py\PerceivedType="text" 

together with

HKEY_CLASSES_ROOT\.py\ShellNew\NullFile=""

works for me on Windows 7.

I have also set HKEY_CLASSES_ROOT\Python default value to "Python Script"


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python"
"Content Type"="text/x-python"
"Python"="Python"
"PerceivedType"="text"

[HKEY_CLASSES_ROOT\.py\ShellNew]
"NullFile"=""

[HKEY_CLASSES_ROOT\Python]
@="Python Script"


回答2:

I have found that the easiest way to do this is with the following method, which I have tested on my Windows 10 PC.

  1. Open Regedit
  2. Navigate to Computer\HKEY_CLASSES_ROOT.py
  3. Right click on the .py key > New > Key
  4. Name the new key "ShellNew"
  5. Inside the ShellNew key, add a new string value
  6. Name the string value "NullFile"
  7. Change the NullFile's value to 1
  8. That's it!

(note: this should work with all plain-text file formats)



回答3:

Use open++. It's easy to configure, and maybe it can do what you want.