Issue
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.
Solution
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
.
Answered By - Paul Panzer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.