弃用reload()??? [英] Deprecating reload() ???

查看:167
本文介绍了弃用reload()???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> >其他惊喜:弃用reload()

重新加载并不像大多数人想象的那样工作:如果你有任何对旧模块的引用,
他们留在身边。他们没有被替换。
这是一个好主意,但实施简单
并不能实现这个想法所承诺的。




我同意它没有真的像大多数人认为的那样工作,但是如果没有reload()你将如何执行与reload()相同的任务?


这是由del sys.modules [''modulename'']"完成然后执行一个

''import''?

我将reload()用于多种目的,知道它是如何工作/不工作的。 />

Lance Ellinghaus

解决方案

" Ellinghaus,Lance" < LA ************** @ eds.com>在留言中写道

新闻:ma ************************************ ** @ pyth on.org ...

其他惊喜:弃用reload()

重新加载并不像大多数人想象的那样工作它确实如此:如果你有任何对旧模块的引用,那么它们就会存在。它们没有被替换。


这是一个好主意,但实现只是
并不能实现这个想法所承诺的。


我同意它并不像大多数人认为的那样真正起作用,但是如果没有重载(),你将如何执行与reload()相同的任务?

这是否可以通过del sys.modules [''modulename'']"来实现。然后执行
''import''?

我将reload()用于多种目的,知道它是如何工作/不工作的。




我通常会想出另一种方法 - 主要是从头开始重新加载整个

程序。在任何情况下,这对我来说都不是一个真正的问题 -

它只是让PythonWin编辑器做到这一点的烦恼

我保持一个命令行打开而不是使用什么(对我而言)

真正破坏了运行的实现。


我希望生活中有很多东西我希望他们按照广告宣传的方式工作。他们不是,所以你应付。


John Roth
Lance Ellinghaus



On星期四,2004年3月11日15:10:59 -0500,Ellinghaus,Lance

< la ************** @ eds.com>写道:

>其他惊喜:弃用reload()


重新加载并不像大多数人想象的那样工作:如果你有得到任何旧模块的参考,
他们留下来。它们没有被替换。


这是一个好主意,但实现只是
并不能实现这个想法所承诺的。


我同意它并不像大多数人认为的那样真正起作用,但是如果没有reload()你会如何执行与reload()相同的任务?




看起来像reload()可以* *通过扫描当前

加载的模块来处理重新加载模块中对象的所有引用,

并将它们重置为新对象。如果新模块中缺少某个对象,则抛出异常。


GvR建议使用''exec'作为替代方案。
http://python.org/doc/essays/ppt/regrets/ 6

我不知道如何解决消除

旧物件的引用的问题。


- 戴夫


Ellinghaus,Lance写道:

我同意它并不像大多数人那样真正起作用人们认为它确实如此,但如果没有reload(),你将如何执行与reload()相同的任务?

这是否可以通过del sys.modules [''modulename来完成'']"然后执行
''import''?




啊,有趣!我一直这样做:


del modulename;导入模块名


但是它没有收到

modulename.py文件的最新更改。


这是比退出Python更好的解决方案和

再次启动它。谢谢!


-

Steven D''Aprano


> > Other surprises: Deprecating reload()

Reload doesn''t work the way most people think
it does: if you''ve got any references to the old module,
they stay around. They aren''t replaced. It was a good idea, but the implementation simply
doesn''t do what the idea promises.



I agree that it does not really work as most people think it does, but how
would you perform the same task as reload() without the reload()?

Would this be done by "del sys.modules[''modulename'']" and then perform an
''import''?

I use reload() for many purposes, knowing how it works/does not work.

Lance Ellinghaus

解决方案

"Ellinghaus, Lance" <la**************@eds.com> wrote in message
news:ma**************************************@pyth on.org...

Other surprises: Deprecating reload()

Reload doesn''t work the way most people think
it does: if you''ve got any references to the old module,
they stay around. They aren''t replaced.


It was a good idea, but the implementation simply
doesn''t do what the idea promises.



I agree that it does not really work as most people think it does, but how
would you perform the same task as reload() without the reload()?

Would this be done by "del sys.modules[''modulename'']" and then perform an
''import''?

I use reload() for many purposes, knowing how it works/does not work.



I usually figure out another way to do it - mostly reload the entire
program from scratch. In any case, it''s not a real issue for me -
it''s just enough of an irritation that the PythonWin editor does it that
I keep a command line open rather than use what is (to me) a
really broken implementation of run.

There are a lot of things in life that I wished worked the way they
are advertised. They don''t, so you cope.

John Roth
Lance Ellinghaus



On Thu, 11 Mar 2004 15:10:59 -0500, "Ellinghaus, Lance"
<la**************@eds.com> wrote:

> Other surprises: Deprecating reload()


Reload doesn''t work the way most people think
it does: if you''ve got any references to the old module,
they stay around. They aren''t replaced.


It was a good idea, but the implementation simply
doesn''t do what the idea promises.



I agree that it does not really work as most people think it does, but how
would you perform the same task as reload() without the reload()?



Seems like reload() could be *made* to work by scanning currently
loaded modules for all references to objects in the reloaded module,
and resetting them to the new objects. If an object is missing from
the new module, throw an exception.

GvR suggests using ''exec'' as an alternative.
http://python.org/doc/essays/ppt/regrets/6
I don''t see how that solves the problem of eliminating references to
old objects.

-- Dave


Ellinghaus, Lance wrote:

I agree that it does not really work as most people think it does, but how
would you perform the same task as reload() without the reload()?

Would this be done by "del sys.modules[''modulename'']" and then perform an
''import''?



Ah, interesting! I''ve been doing this:

del modulename; import modulename

but it doesn''t pick up any recent changes to the
modulename.py file.

That''s a better solution than exiting Python and
starting it up again. Thanks!

--
Steven D''Aprano


这篇关于弃用reload()???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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