编程语言
首页 > 编程语言> > 从python中的weakref代理获取常规引用

从python中的weakref代理获取常规引用

作者:互联网

有没有办法为我得到弱代理的对象获得正确的引用?

我已经浏览了weakref模块的文档,并且没有在那里得到答案,或者通过手动戳一个weakproxy对象.

解决方法:

您可以通过调用它来从weakref对象获取引用:

obj = ref()

weakref docs

Weak reference objects have no attributes or methods, but do allow the
referent to be obtained, if it still exists, by calling it. If the referent no longer exists,
calling the reference object returns None.

这对代理对象不起作用,我没有看到从weakref代理获取弱引用对象或对实际对象的引用的方法.

标签:python,weak-references
来源: https://codeday.me/bug/20190709/1407637.html