我正在阅读有关异常处理的教程,并且必须在名为exception.py的模块中编写这段代码
def convert(s):
try:
x = int(s)
prnit("Conversion done. x=", x) #there is a typo
except ValueError:
print("Failed")
x = -1
return x
然后从REPL我导入这个函数
from exception import convert
并按预期转换(7.7)返回NameError: name 'prnit' is not defined
。之后我纠正了错字并再次做了from exception import convert
。但错误仍然存在。为什么不导入新模块?
我不得不exit()
然后REPL并再次导入它然后它工作正常和预期。
导入缓存在Python中,您可以在official documentation中阅读它。
有一些方法可以使导入缓存无效,但强烈建议不要这样做。
非常简单:模块被缓存,请参阅主题(5.3.1)上的Python documentation。