sheldonzy
sheldonzy

Reputation: 5961

Spyder doesn't detect changes in imported python files

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.

Upvotes: 3

Views: 2006

Answers (2)

Carlos Cordoba
Carlos Cordoba

Reputation: 34156

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

Upvotes: 2

Paul Panzer
Paul Panzer

Reputation: 53029

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.

Upvotes: 2

Related Questions