How to Execute a Python Script in Notepad++

How to Execute a Python Script in Notepad++?

First option: (Easiest, recommended)

Open Notepad++. On the menu go to: Run -> Run.. (F5). Type in:

C:\Python26\python.exe "$(FULL_CURRENT_PATH)"

Now, instead of pressing run, press save to create a shortcut for it.

Notes

  • If you have Python 3.1: type in Python31 instead of Python26
  • Add -i if you want the command line window to stay open after the script has finished

Second option

Use a batch script that runs the Python script and then create a shortcut to that from Notepad++.

As explained here: http://it-ride.blogspot.com/2009/08/notepad-and-python.html


Third option: (Not safe)

The code opens “HKEY_CURRENT_USER\Software\Python\PythonCore”, if the key exists it will get the path from the first child key of this key.

Check if this key exists, and if does not, you could try creating it.

How do you run a Python script from within Notepad++ but using powershell and in the directory of the script?

To be able to run a Python script in Powershell you can press F5 to open the run dialog box, to run the python script in powershell normally you can use;

powershell.exe -noexit -command "cd "$(CURRENT_DIRECTORY)"; python -i "$(FULL_CURRENT_PATH)""

This however opens up Powershell in an ugly format similar to what cmd looks like by default however it does have all the features, it also does not run the script from the directory so relative paths don't work. To make the Powershell look normal you should run it from the shortcut that is in the start menu, to allow it to work if the file path has a space in it you should put a \ before the quotation marks. The working run command is therefore;

"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk" -noexit -command cd \"$(CURRENT_DIRECTORY)\"; python -i \"$(FULL_CURRENT_PATH)\"


Related Topics



Leave a reply



Submit