在 IDLE 中重新加载方法或对象

发布于 2024-08-22 06:31:48 字数 173 浏览 1 评论 0原文

当使用空闲时,我知道如果模块发生这样的变化,您可以重新加载模块:

import foo
reload(foo)

如果我只导入模块的一部分,有没有办法以类似的方式重新加载它?

from foo import bar

when using idle, I know you can reload a module if it's changed like this:

import foo
reload(foo)

if I only import part of a module, is there a way to reload it in a similar matter?

from foo import bar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情深缘浅 2024-08-29 06:31:48

不,reload 必须重新运行整个模块。

请注意,reload 令人困惑,并且不具备保持一致的能力。最好重新启动解释器。

No, reload has to re-run the whole module.

Note that reload is confusing and does not have the ability to be consistent. It's much better to restart the interpreter.

岛歌少女 2024-08-29 06:31:48

不,毕竟您必须导入 foo,然后重新加载(foo)。

No. You'll have to import foo, then reload(foo), after all.

念﹏祤嫣 2024-08-29 06:31:48

http://docs.python.org/2/library/functions.html#reload

它说:

“如果一个模块使用 from ... import 从另一个模块导入对象
...,为其他模块调用 reload() 不会重新定义
从它导入的对象 - 解决这个问题的一种方法是重新执行
from 语句,另一种是使用 import 和限定名称
(模块。名称)。”

但是语句不是很清楚。

http://docs.python.org/2/library/functions.html#reload

It says:

"If a module imports objects from another module using from ... import
..., calling reload() for the other module does not redefine the
objects imported from it — one way around this is to re-execute the
from statement, another is to use import and qualified names
(module.name) instead."

But the statements is not very clear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文