Community
    • Login

    Run Only Selected Text with Python?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    python
    4 Posts 2 Posters 790 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      chigkim
      last edited by

      Is there a way to run only selected text with Python?
      NPPExec plugin seems to let you run only an entire saved script.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @chigkim
        last edited by

        @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)

        C 1 Reply Last reply Reply Quote 2
        • C
          chigkim @PeterJones
          last edited by

          @PeterJones Thanks for the response.
          If I select 3+3 and run python "$(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.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @chigkim
            last edited by PeterJones

            @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.

            1 Reply Last reply Reply Quote 4
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors