Python 如何让inspect.getsource响应源代码中的更改?
我创建了两个文件:Python 如何让inspect.getsource响应源代码中的更改?,python,inspection,Python,Inspection,我创建了两个文件: #test_func.py def test(): print('hello') 及 从IPython或其他交互式shell运行import test\u inspect,打印正确的内容: def test(): print('hello') 但如果我将test_func.py编辑并保存为: #test_func.py def test(): print('good bye') 我仍然得到: def test(): print('hell
#test_func.py
def test():
print('hello')
及
从IPython或其他交互式shell运行import test\u inspect
,打印正确的内容:
def test():
print('hello')
但如果我将test_func.py编辑并保存为:
#test_func.py
def test():
print('good bye')
我仍然得到:
def test():
print('hello')
当我从shell运行重新加载(test\u inspect)
时。如何说服inspect
模块重新读取源文件
(如果你必须知道我为什么要这样做,我会在评论中详细说明,但现在,我只想知道是否有解决方法,或者检查模块是否有一些基本的东西可以防止这种情况发生)这应该可以做到:
import linecache
linecache.clearcache()
啊。好多了。谢谢。我认为这实际上是
linecache
或inspect
中的一个bug,应该在python 3.5中修复。谢谢你的解决办法。看见
import linecache
linecache.clearcache()