This should do the trick:
import linecache
linecache.clearcache()
Pergunta
I make two files:
#test_func.py
def test():
print('hello')
and
#test_inspect.py
import inspect
import test_func
reload(inspect)
reload(test_func)
reload(inspect)
reload(test_func)
print inspect.getsource(test_func.test)
Running import test_inspect
from IPython or other interactive shell prints the right thing:
def test():
print('hello')
but if I edit and save test_func.py to be:
#test_func.py
def test():
print('good bye')
I still get:
def test():
print('hello')
when I run reload(test_inspect)
from the shell. How can I convince the inspect
module to re-read the source file?
(If you must know why I want to do this, I will elaborate in the comments, but for right now, I'd like to simply know if there is a workaround for this or if there is something fundamental about the inspect module that prevents this)
Solução
This should do the trick:
import linecache
linecache.clearcache()