【发布时间】:2016-01-31 01:45:51
【问题描述】:
我在两个文件中有以下玩具代码:
文件b.py:
def test_b():
print "b"
文件a.py:
从 b 导入 test_b
def test_a():
print "a"
test_b()
然后我运行 python REPL:
>>> execfile("a.py")
>>> test_a()
a
b
然后我将b.py修改为:
def test_b():
打印“bb”
并在 REPL 中运行:
>>> execfile("b.py")
>>> test_a()
a
bb
现在一切都很好。现在我将a.py修改为:
from b import test_b
def test_a():
print "aa"
test_b()
现在我遇到了 REPL:
>>> execfile("a.py")
>>> test_a()
aa
b
自从 REPL 获得了旧版本的 b.py 后,这已经不再适用了。 Python 在加载文件时似乎正在做一些缓存,我的问题是:有没有办法强制它不这样做?我找不到函数excefile 的合适选项。
【问题讨论】:
-
这个答案对您的问题有帮助吗? stackoverflow.com/a/2918951/758446
-
@BlackVegetable 看起来像,谢谢。我现在要测试它。
标签: python read-eval-print-loop