3

I'm using Spyder 3.2.4 (Python 3.6). Spyder doesn't detect changes in imported python files. For example:

test2.py:

def func():
    return 5

test1.py:

import test2

a = test2.func()
print(a)

When I wrote those classes, and saved them (in the same working directory), and ran test1.py the output was 5.

BUT when I change the function in test2.py, to like:

def func():
    return 10

Save it, and then run python1.py, I still get 5. Only when I save, exit the IDE, and return, I will get the changed code (10).

This behavior is going on since I started using Spyder (few months by now), and it's super annoying. Help would be appreciated.

sheldonzy
  • 5,505
  • 9
  • 48
  • 86
  • Not sure this is spyder related. You could try and use `importlib.reload`. – Paul Panzer Dec 09 '17 at 17:28
  • When I'm using Intellij IDE with the python plugin it doesn't happen, so I'm pretty sure it is Spyder related. – sheldonzy Dec 09 '17 at 17:34
  • What I meant is that this is a python feature. If you import a module, change it in the background and then import again python will not pick up the changes. You either have to restart the interpreter or you can use `importlib.reload`. – Paul Panzer Dec 09 '17 at 17:38
  • wow thanks. It works now. I didn't know about it. In intellij it happens automatically? answer as an answer to the question, so I'll be able to accept it. – sheldonzy Dec 09 '17 at 17:50

2 Answers2

2

What you are experiencing is a Python feature. Modules are initialized when first imported and kept in a cache. Each subsequent import uses the cache, so the module code is not run again.

What in most cases is an eminently reasonable economy, is rather annoying when developing. You can force python to reload a module using importlib.reload.

Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
2

(Spyder maintainer here) This is a know issue and it'll fixed in our 3.2.5 version, to be released on December/2017.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124