在file1.py:旧代码已被修改
def foo():
import file2
print "I'm the old file1.py"
file2.bar()
if __name__ == '__main__':
foo()
在file2.py
print "I'm the old file2.py"
def bar():
print "I'm in the old file2.bar()"
在下面的交互式会话的第5行,进行修改后,到file1.py和file2.py将old
这个词的所有三次出现更改为new
,但file2.py中的new
代码仍未被使用。
[email protected]:~/sandpit$ ipython
>>> run file1.py
I'm the old file2.py
I'm the old file1.py
I'm in the old file2.bar()
>>> !rm file2.pyc
>>> # modify file1, file2
>>> run file1.py
I'm the new file1.py
I'm in the old file2.bar()
从哪里得到file2.py的旧代码?
我必须误解的东西,因为我认为(从IPython的帮助上run
):
该文件命名空间中的最初只包括
__name__ == '__main__'
和sys.argv
指示构建执行。因此,它 看到它的环境,如果它正在运行一个独立的程序
我已经删除了.pyc文件的文件,并且可以从命令whos
看到,出现在名字空间中没有文件2模块。但为什么第二次运行file1时导入不会再执行?
“IPython.lib.dreload”中的“deep reload”(或0.10.x中的“IPython.deep_reload”)可能会帮助您解决这个问题。 –
如果有人有类似的情况:我虽然我有类似的问题,除了我用普通的python(而不是解释器模式)运行代码。即使删除'.pyc'文件也没有帮助。事实证明,当我向上滚动时(使用Vi插件),只是Tmux向我展示了旧输出。 –
你刚刚基本上每次运行一个新的'ipython'会话吗? –