重新加载模块给出 NameError:未定义名称“重新加载" [英] Reloading module giving NameError: name 'reload' is not defined

查看:62
本文介绍了重新加载模块给出 NameError:未定义名称“重新加载"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新加载我已经在 Python 3 中导入的模块.我知道您只需要导入一次并再次执行 import 命令将不会执行任何操作.

I'm trying to reload a module I have already imported in Python 3. I know that you only need to import once and executing the import command again won't do anything.

执行 reload(foo) 会出现这个错误:

Executing reload(foo) is giving this error:

Traceback (most recent call last):
    File "(stdin)", line 1, in (module)
    ...
NameError: name 'reload' is not defined

错误是什么意思?

推荐答案

reload 是 Python 2 中的内置函数,但不是 Python 3 中的内置函数,因此您会看到预期的错误.

reload is a builtin in Python 2, but not in Python 3, so the error you're seeing is expected.

如果你真的必须在 Python 3 中重新加载一个模块,你应该使用:

If you truly must reload a module in Python 3, you should use either:

这篇关于重新加载模块给出 NameError:未定义名称“重新加载"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆