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
cHl0aG9uIC1jICJwcmludCgkKENVUlJFTlRfV09SRCkpIgcan be easily decoded to hand you the answer. But any further questions about how to use python.exe are off topic here.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login