2
鑑於此代碼,我該如何告訴python不使用緩存的源代碼或重新加載?python importlib,如何使動態加載文件的緩存失效
import importlib.util
spec = importlib.util.spec_from_file_location('test', '~/myfile.py')
test = importlib.util.module_from_spec(spec)
spec.loader.exec_module(test)
test.do_stuff()
當myfile.py的內容改變它沒有拿起,我假設,因爲它被緩存。調用importlib.invalidate_caches()
沒有幫助,importlib.reload
導致錯誤說測試不在sys.modules