Menu

changes in imported .py files don't get picked up

Help
Sasumner
2015-06-05
2015-06-15
  • Sasumner

    Sasumner - 2015-06-05

    Say I create a new pythonscript file, a.py:

    from Npp import *
    from b import *
    console.write("I'm a\n")
    b = B()
    b.blah()
    

    and a new file called b.py:

    from Npp import *
    class B:
        def blah(self):
            console.write("I'm b 1\n")
    

    When I run a.py (via N++ Plugins -> Pythonscript -> Scripts -> a.py), it outputs to the console:

    I'm a
    I'm b 1
    

    HOWEVER, when I make a change to b.py (like attempting to output "I'm b 2" and save it, of course), and then run a.py again, my output doesn't change (still get "I'm b 1"). Why is this?

    I find that if I quit N++ and restart it, then my change to b.py gets picked up.

    Who out there knows how to avoid this (i.e., how do I make it work "right", where I can just edit+save my files, and have this aspect of things work correctly)?

     
    • Dave W.

      Dave W. - 2015-06-05

      I seem to remember from "Learning Python", some edition, the part about
      "How Python Runs Modules vs. How YOU Run Modules", or such, that modules
      imported once and then at some point 'import'ed again, are not actually
      re-loaded. You have to run the built-in 'reload' function to actually
      accomplish that. I suspect you could just run that from the command line in
      PS. Check out the doc...
      https://docs.python.org/2/library/functions.html?highlight=reload#reload
      vs
      https://docs.python.org/2/reference/simple_stmts.html#the-import-statement

      Hope this helps.

      On Fri, Jun 5, 2015 at 10:48 AM, Sasumner sasumner@users.sf.net wrote:

      Say I create a new pythonscript file, a.py:

      from Npp import from b import console.write("I'm a\n")b = B()b.blah()

      and a new file called b.py:

      from Npp import *class B:
      def blah(self):
      console.write("I'm b 1\n")

      When I run a.py (via N++ Plugins -> Pythonscript -> Scripts -> a.py), it
      outputs to the console:

      I'm a
      I'm b 1

      HOWEVER, when I make a change to b.py (like attempting to output "I'm b 2"
      and save it, of course), and then run a.py again, my output doesn't change
      (still get "I'm b 1"). Why is this?

      I find that if I quit N++ and restart it, then my change to b.py gets
      picked up.

      Who out there knows how to avoid this (i.e., how do I make it work
      "right", where I can just edit+save my files, and have this aspect of
      things work correctly)?


      changes in imported .py files don't get picked up
      https://sourceforge.net/p/npppythonscript/discussion/1188886/thread/03698ffa/?limit=250#1a0d


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/npppythonscript/discussion/1188886/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Jacob

    Jacob - 2015-06-05

    Strange -- I've been making modifications to my scripts and running them without closing, and it works fine. Where do you have your script saved?
    Mine's in the ...\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts
    directory.

     
  • Sasumner

    Sasumner - 2015-06-15

    Jacob, I think you're missing the point. The "problem" is not in a main script, but in code that gets imported into the main script.

    Dave W, thanks for your input. After doing some reading and experimenting, I think I've decided to just live with this behavior. Code that I am importing is like "library" code anyway, supposedly separately debugged, so there would be no reason to change it when it is imported into something else. That being said, I sometimes find myself adding to the "library" functionality and then getting mildly upset when it isn't brought in without a restart of N++.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.