是否可以恢复导入模块?

2024-10-03 11:23:29 发布

您现在位置:Python中文网/ 问答频道 /正文

很多时候,我试图在交互模式下导入一个python文件作为一个模块,但是我注意到其中一个函数有错误,所以我必须去修复它,然后我必须退出interepter中的python并重新打开它,然后在我的非常慢的pc上重新导入这个模块,这需要很长时间,如果我注意到另一个错误,那么这只是一个棘手的任务。在

我如何从python interepter中删除一个模块而不完全删除它(允许以后重新导入),而不重新启动python?在


Tags: 模块文件函数错误模式pc棘手interepter
1条回答
网友
1楼 · 发布于 2024-10-03 11:23:29

您可以在进行更改后^{}创建模块:

reload(my_module)

根据文件:

Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version without leaving the Python interpreter. The return value is the module object (the same as the module argument).

相关问题 更多 >