In file1.py:
def foo():
import file2
print "I'm the old file1.py"
file2.bar()
if __name__ == '__main__':
foo()
In file2.py
print "I'm the old file2.py"
def bar():
print "I'm in the old file2.bar()"
On line 5 of the interactive session below, after making modifications to file1.py and file2.py changing all three occurrences of the word old
to new
, the new
code in file2.py is still not used.
wim@wim-ubuntu:~/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()
Where is it getting the old code from file2.py from?
I must misunderstand something, because I thought (from ipython help on run
):
The file is executed in a namespace initially consisting only of
__name__ == '__main__'
andsys.argv
constructed as indicated. It thus sees its environment as if it were being run as a stand-alone program
I've deleted the .pyc file, and can see from the command whos
that there is no file2 module present in the namespace. But why is the import not executed again when running file1 a second time?
IPython.lib.dreload
(orIPython.deep_reload
in 0.10.x) might help you with this. – Nealson.pyc
files was of no help. As it turned out, it was just Tmux showing me old output when I scrolled up (using the Vi plugin). – Wagonipython
session each time? – Anastomosis