• Login
Community
  • Login

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

Scheduled Pinned Locked Moved General Discussion
7 Posts 3 Posters 4.8k 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.
  • H
    hycmos
    last edited by hycmos Dec 19, 2017, 2:20 AM Dec 19, 2017, 2:17 AM

    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. ^_^.

    A 1 Reply Last reply Dec 20, 2017, 1:37 AM Reply Quote 0
    • A
      Alan Kilborn @hycmos
      last edited by Dec 20, 2017, 1:37 AM

      @hycmos

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

      1 Reply Last reply Reply Quote 0
      • H
        hycmos
        last edited by hycmos Dec 20, 2017, 8:07 AM Dec 20, 2017, 8:04 AM

        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.

        S 1 Reply Last reply Dec 20, 2017, 12:55 PM Reply Quote 0
        • S
          Scott Sumner @hycmos
          last edited by Dec 20, 2017, 12:55 PM

          @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
          • H
            hycmos
            last edited by hycmos Dec 21, 2017, 3:17 AM Dec 21, 2017, 3:16 AM

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

            S 1 Reply Last reply Dec 21, 2017, 1:34 PM Reply Quote 0
            • S
              Scott Sumner @hycmos
              last edited by Scott Sumner Dec 21, 2017, 1:35 PM Dec 21, 2017, 1:34 PM

              @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!]

              H 1 Reply Last reply Dec 22, 2017, 5:12 AM Reply Quote 0
              • H
                hycmos @Scott Sumner
                last edited by hycmos Dec 22, 2017, 5:13 AM Dec 22, 2017, 5:12 AM

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