Spyder无法检测到导入的python文件中的更改 [英] Spyder doesn't detect changes in imported python files
问题描述
我正在使用Spyder 3.2.4(Python 3.6). Spyder不会检测到导入的python文件中的更改.例如:
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)
当我编写这些类并将其保存(在同一工作目录中)并运行 test1.py 时,输出为5
.
When I wrote those classes, and saved them (in the same working directory), and ran test1.py the output was 5
.
但是当我更改 test2.py 中的功能时,就像这样:
BUT when I change the function in test2.py, to like:
def func():
return 10
保存它,然后运行 python1.py ,我仍然得到5
.仅当我保存,退出IDE并返回时,我才会获得更改后的代码(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
).
自从我开始使用Spyder以来,这种行为一直在发生(到目前为止已经有几个月了),这真是太烦人了.帮助将不胜感激.
This behavior is going on since I started using Spyder (few months by now), and it's super annoying. Help would be appreciated.
推荐答案
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.
在大多数情况下,显着的合理经济在发展时相当烦人.您可以使用importlib.reload
强制python重新加载模块.
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
.
这篇关于Spyder无法检测到导入的python文件中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!