3 ms·
I think because of the way import works, that a reload wouldn't update anything that the module you're reloading imports. $echo -e "def foo():\n\tprint 'bar'
by tedshroyer 18y ago
I think because of the way import works, that a reload wouldn't update anything that the module you're reloading imports.
$echo -e "def foo():\n\tprint 'bar'" > a.py
$echo -e "import a\ndef bar():\n\ta.foo()" > b.py
$python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
>>>import b
>>>b.bar()
bar
>>>f = open('a.py', 'w')
>>>f.write("def foo():\n\tprint 'changed'")
>>>f.close()
>>>reload(b)
<module 'b' from 'b.pyc'>
>>> # Notice that it imported from 'b.pyc' not 'b.py'
... b.bar()
bar
>>>reload(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>>#But I need to update a
...reload(b.a)
<module 'a' from 'a.py'>
>>>#That loaded from 'a.py'
...b.bar()
changed
>>>exit()
edit
#You could have done it like this too
>>>import a
>>>import b
>>>b.bar()
bar
>>>###Something changes a.py
>>>reload(a)
>>>b.bar()
changed