How To Use Notepad++ For Python
I besides wanted to run python files directly from Notepad++. Nigh mutual selection found online is using builtin option Run
. Then you take 2 options:
-
Run python file in panel (in Windows it is Command Prompt) with code something similar this (links: ):
C:\Path\to\Python\python.exe "$(FULL_CURRENT_PATH)"
(If your panel window immediately closes afterwards running so you tin add
cmd /k
to your code. Links: ) This works fine, and you can fifty-fifty run files in interactive fashion by adding-i
to your code (links: ). -
Run python program in IDLE with code something similar this (links: , in these links
C:\Path\to\Python\Lib\idlelib\idle.py
is used, simply I am usingC:\Path\to\Python\Lib\idlelib\idle.bat
instead, becauseidle.bat
sets the right current working directory automatically):C:\Path\to\Python\Lib\idlelib\idle.bat "$(FULL_CURRENT_PATH)"
Actually, this doesn't run your program in IDLE Beat out, but instead it opens your python file in IDLE Editor so you need to click
Run Module
(or click F5) to run the plan. So it opens your file in IDLE Editor and so you lot need run it from there, which defeats the purpose of running python files from Notepad++.Simply, searching online, I found option which adds '-r' to your code (links: ):
C:\Path\to\Python\Lib\idlelib\idle.bat -r "$(FULL_CURRENT_PATH)"
This will run your python program in IDLE Crush and because information technology is in IDLE it is by default in interactive way.
Trouble with running your python files via builtin Run
option is that each time yous run your python file, y'all open new console or IDLE window and lose all output from previous executions. This might not be important to some, simply when I started to program in python, I used Python IDLE, and so I got used to running python file multiple times in same IDLE Beat out window. Also problem with running python programs from Notepad++ is that y'all need to manually save your file and then click Run
(or press F5). To solve these issues (AFAIK*) you need to employ Notepad++ Plugins. The best plugin for running python files from Notepad++ is NppExec. (I also tried PyNPP and Python Script. PyNPP runs python files in console, it works, merely you can do that without plugin via builtin Run
option and Python Script is used for running scripts that collaborate with Notepad++ so you lot can't run your python files.) To run your python file with NppExec plugin you lot need to go to Plugins -> NppExec -> Execute
and then blazon in something like this (links: ):
C:\Path\to\Python\python.exe "$(FULL_CURRENT_PATH)"
With NppExec yous can also salvage your python file earlier run with npp_save
command, fix working directory with cd "$(CURRENT_DIRECTORY)"
command or run python program in interactive fashion with -i
command. I plant many links ( ) online that mention these options, but best use of NppExec to run python programs I plant at NppExec'due south Transmission which has affiliate iv.6.iv. Running Python & wxPython
with this code:
npp_console - // disable any output to the Console npp_save // save current file (a .py file is expected) cd "$(CURRENT_DIRECTORY)" // use the current file's dir set local @exit_cmd_silent = exit() // allows to exit Python automatically set local PATH_0 = $(SYS.PATH) // current value of %PATH% env_set PATH = $(SYS.PATH);C:\Python27 // use Python 2.seven npp_setfocus con // set the focus to the Console npp_console + // enable output to the Console python -i -u "$(FILE_NAME)" // run Python'south program interactively npp_console - // disable any output to the Panel env_set PATH = $(PATH_0) // restore the value of %PATH% npp_console + // enable output to the Console
All yous need to do is re-create this code and change your python directory if you use some other python version (e.g.* I am using python 3.4 so my directory is C:\Python34
). This code works perfectly, but there is one line I added to this code so I can run python plan multiple times without loosing previous output:
npe_console m- a+
a+
is to enable the "append" way which keeps the previous Console's text and does non clear it.
1000-
turns off console's internal messages (those are in green color)
The final code that I use in NppExec'southward Execute window is:
npp_console - // disable whatsoever output to the Console npp_save // save current file (a .py file is expected) cd "$(CURRENT_DIRECTORY)" // use the current file'due south dir set local @exit_cmd_silent = exit() // allows to exit Python automatically set local PATH_0 = $(SYS.PATH) // electric current value of %PATH% env_set PATH = $(SYS.PATH);C:\Python34 // utilize Python 3.four npp_setfocus con // set the focus to the Panel npe_console m- a+ npp_console + // enable output to the Panel python -i -u "$(FILE_NAME)" // run Python's program interactively npp_console - // disable any output to the Console env_set PATH = $(PATH_0) // restore the value of %PATH% npp_console + // enable output to the Console
You can save your NppExec's code, and assign a shortcut central to this NppExec'south script. (You need to open up Advanced options of NppExec's plugin, select your script in the Associated script
drop-down listing, press the Add/Modify
, restart Notepad++ , go to Notepad++'es Settings
-> Shortcut Mapper
-> Plugin commands
, select your script, click Modify
and assign a shortcut key. I wanted to put F5
equally my shortcut fundamental, to do that you need to modify shortcut cardinal for builtin option Run
to something else first.) Links to capacity from NppExec's Transmission that explain how to salvage you lot NppExec's code and assign a shortcut key: NppExec'south "Execute..."
, NppExec's script
.
P.S.*: With NppExec plugin y'all can add Highlight Filters
(establish in Console Output Filters...
) that highlight certain lines. I use information technology to highlight mistake lines in red, to exercise that you need to add Highlight masks
: *File "%FILE%", line %LINE%, in <*>
and Traceback (most recent call last):
similar this.
How To Use Notepad++ For Python,
Source: https://stackoverflow.com/questions/1702586/how-to-execute-a-python-script-in-notepad
Posted by: davidsonnoby1984.blogspot.com
0 Response to "How To Use Notepad++ For Python"
Post a Comment