Using Python with Notepad++
-
What is the recommended way of using Python with Notepad++?
(1) Should we use the latest Python 3 from https://www.python.org/downloads/windows/ ?
(2) Which, if any, Notepad++ plugins are recommended for just writing and running Python when learning the language?
(3) Which Notepad++ plugins are recommended for writing Python code to examine and modify the context of Notepad++ buffers?
(4) Is the “NppExec” plugin the preferred way of working with Python?Notepad++'s plugin manager shows three Python plugins. Following the links found in the brief details shown by the plugin manager is not very informative. The pages left me concerned about versions and what has been kept up to date, or not.
-
I guess there is no simple yes/no answer.
If you want to start learning the language I would install python 3.
Python 2’s lifetime ends in 2020 (afaik).If you want to interact with notepad++ and scintilla - then python script plugin
is handy as it has already wrapped most of the functionality. The plugin has
python2 included. You could use the future imports in your scripts to make it
look like more python3 but there are still differences. Not many and nothing
which can’t be easily learned when switching - you just need to be aware.
See https://wiki.python.org/moin/Python2orPython3 for more details.In theory, you could use python3 together with ctypes to do the same
as the python script plugin but then you have to wrap each function by yourself.For non python script pluign usage.
NppExec makes it easy to run your python code with different interpreters
and with different command line parameters and does support output
manipulation. What I mean is, if python throws an error you could define rules
which would result in highlighting this errors and if clicking on it, it will redirect or
open the source file for you. So yes, I recommend using it.Concerning the plugins, I’m only using python script plugin and did not test
the others so I cannot say if it is worth installing it or not.Cheers
ClaudiaBtw. nothing speaks against installing and using py3 and python script plugin together.
I’m using it that way. -
Thank you, @Claudia. That is exactly the type of information I wanted.
-
Python 3.6.0 and Notepad++
I would like to run a script (macro, etc.) that 1) saves the N++ *.py file, then runs the script to the Python shell.
From the Notepad++ run menu I run:
“C:\Program Files (x86)\Python36-32\Lib\idlelib\idle.bat” -r “$(FULL_CURRENT_PATH)”
(By the way, I have that saved as a shortcut: Alt+Shift+P)
For any other computer it would be:
“C:\ …insert your path here… \Lib\idlelib\idle.bat” -r “$(FULL_CURRENT_PATH)”This opens the Python 3.6.0 Shell and runs the Python code. However, it does not close save the *.py file prior to running. Also, it does not close any open Python Shell windows (optional, but it might be nice).
I would like to run a script that:
- Saves my current *.py file that I am editing in N++,
- Close any open Python Shell windows, (optional, but nice)
- run: “C:\Program Files (x86)\Python36-32\Lib\idlelib\idle.bat” -r “$(FULL_CURRENT_PATH)”
all in one shortcut.
How can I modify the code to for this?
By the way, what is “-r” after “\idle.bat”?
-
if you want to run/start another application from within notepad then there is no save
way to interact with it. It could always happen something unforeseen which breaks a logic.
What I always wonder is why would one edit a python file in notepad++ and then want to start it using idle?
Why not using idle at all if idle is the preferred way?If it is just about executing a script, npp can, as you already showed, handle this and when using NppExec plugin
you can even save your file before executing it. Shell doesn’t need to be closed as it gets executed via
python interpreter and output is captured. So a configuration for NppExec plugin coud look like thisnpp_save
cd “WHERE_EVER_YOUR_PYTHON_3.6_INSTALLATION_IS”
python “$(FULL_CURRENT_PATH)”Save it - done.
-r -> this might help.
Cheers
Claudia -
Claudia, thanks for this:
-
N++ is better than Python idle because each line of code in N++ is numbered, whereas idle in not. That makes it difficult to troubleshoot a file with 1000 lines of code.
-
Great, I did not know about that plug-in.
-
A lot of people use lmddgfy sarcastically, but that link you sent me helped me a lot because I am not familiar enough with idle to determine the keywords for a ddg search.
Thanks!
-