Community
    • Login

    Run Only Selected Text with Python?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    python
    4 Posts 2 Posters 1.7k Views 2 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            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

            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
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors