Run Only Selected Text with Python?
-
Is there a way to run only selected text with Python?
NPPExec plugin seems to let you run only an entire saved script. -
@chigkim ,
$(CURRENT_WORD)
works in NppExec (or the Run menu’s Run… command) to give the contents of the active selection. This is documented in the Plugins > NppExec > Docs >NppExec_HelpAll.txt
(and NPP User Manual > Config Files > User Defined Commands) -
@PeterJones Thanks for the response.
If I select 3+3 and runpython "$(CURRENT_WORD)"
I get:
python.exe: can’t open file ‘…Notepad++64\3’: [Errno 2] No such file or directory
I guess it’s trying to run the file 3+3, not actually run the text 3+3 in python. -
@chigkim ,
Then you need to learn how to run python code from a command-line argument instead of from a script. That’s a python question, not a Notepad++ question.
The Notepad++ specific part of your question is how to access the selection in an NppExec script (or Run command), and you now have that information.
Though I’ll thow you a fish: if you can figure out how to use Notepad++'s default plugins, then
cHl0aG9uIC1jICJwcmludCgkKENVUlJFTlRfV09SRCkpIg
can be easily decoded to hand you the answer. But any further questions about how to use python.exe are off topic here.