Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Share my method of "how to run python script in Notepad++"

    General Discussion
    3
    7
    4214
    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.
    • hycmos
      hycmos last edited by hycmos

      1. Why use Python?
      I was writed some small tools with VB6 to improve the job efficency. But VB6 is old, is not supported. Python is so popular. So… After try Pyton, I found that Python is more efficent than VB6, and easier.
      So I finished one python script, named Mytool.py. and its copy Mytool.pyw.

      2.Python Script in Notepad++
      Objective: click menu “Run” --> “Mytool”, then the Mytool.py (or Mytool.pyw) runs.
      Procedure(assume Mytool.pyw is in $(NPP_DIRECTORY)\myplugins\Mytool):
      (1) Is it ok that double-click on Mytool.py?
      if OK? then go to (2)
      if NOt? add environment variable (depend on your Python install location)
      “PYTHONPATH” = “C:\Users\myPC\AppData\Local\Programs\Python\Python36-32”
      add more “path” = “C:\Users\myPC\AppData\Local\Programs\Python\Python36-32” (Import dont delete your old path, just add more Python location!!!)
      after add the two variable, try double-click on Mytool.py, it should be ok.

      (2) Close Notepad++, open “\Program Files (x86)\Notepad++\shortcuts.xml” by notepad:

      • find <UserDefinedCommands>
      • add one line: <Command name=“Mytool” Ctrl=“no” Alt=“yes” Shift=“no” Key=“119”>$(NPP_DIRECTORY)\myplugins\Mytool\Mytool.pyw</Command>
      • save and exit.

      (3) Run Notepad++
      if OK, then Done!!
      if Not, maybe the Mytool just flash and then disappear. The reason is bad “python current working dir, CWD”.
      To correct the CWD, need modify the Mytool.py (and pyw), add the belowe lines into Mytool.py (after import os,…)
      if os.getcwd() != sys.path[0]:
      os.chdir(sys.path[0])

      then re-run NP++, click “run”–> “Mytool”, try again. It should be ok! For me , It is OK. ^_^.

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @hycmos last edited by

        @hycmos

        I’ve read this a few times and have no idea what it is saying??

        1 Reply Last reply Reply Quote 0
        • hycmos
          hycmos last edited by hycmos

          Sorry,This is my first post in this forum.
          It seems a topic can not be modified after 180s. >_<.
          I did not know this before. I sent out a rough draft.

          The topic is about how to run Python script in NP++.
          Before this, I try to find solution in this forum to run Python script by menu “Tools”.
          I didnot find it. Some solution are not for me.

          Scott Sumner 1 Reply Last reply Reply Quote 0
          • Scott Sumner
            Scott Sumner @hycmos last edited by

            @hycmos ,@Alan-Kilborn

            There is a pretty good (disclaimer: I wrote it ! ) step-by-step explanation of some methods of running Pythonscripts in this thread:

            https://notepad-plus-plus.org/community/topic/14703/run-python-script-pythonscript-plugin-with-a-shortcut

            1 Reply Last reply Reply Quote 0
            • hycmos
              hycmos last edited by hycmos

              @Scott-Sumner said:

              @hycmos ,@Alan-Kilborn

              There is a pretty good (disclaimer: I wrote it ! ) step-by-step explanation of some methods of running Pythonscripts in this thread:

              https://notepad-plus-plus.org/community/topic/14703/run-python-script-pythonscript-plugin-with-a-shortcut

              By this method in this 14703 thread, a plugin must be installed. That is why I try new method.
              My method in the topic do not need any NP++ plugin, just only Python is installed in PC.

              Scott Sumner 1 Reply Last reply Reply Quote 0
              • Scott Sumner
                Scott Sumner @hycmos last edited by Scott Sumner

                @hycmos

                Ah, thought you were talking about “Pythonscript” (the scripting plugin) when in reality you were talking about “Python scripts”.

                For your usage I prefer “Python programs” as when you talk about Python “scripts” people that don’t know get the impression that Python programming is not real programming. I guess they equate it to batch file writing, or shell “scripts”, or something very trivial…who knows, can’t read minds… [Certainly not trying to trivialize batch or shell scripting with that comment!]

                hycmos 1 Reply Last reply Reply Quote 0
                • hycmos
                  hycmos @Scott Sumner last edited by hycmos

                  @Scott-Sumner
                  Actually, I am not good at programming. I used VB6 to write code to implent some small tools before.
                  But Billgates dont update VB6. So I must sellect another language. I decide to use Python just because many peple talk it on web. I have no idea about other languages.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors