Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 243
sheldonzy Avatar asked Jun 08 '26 19:06

sheldonzy


1 Answers

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.

like image 197
Paul Panzer Avatar answered Jun 10 '26 11:06

Paul Panzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!