通过 id() 获取对象? [英] Get object by id()?

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

问题描述

假设我有一个 Python 对象的 id,我通过执行 id(thing) 检索到它.如何通过给我的 ID 号再次找到 thing?

Let's say I have an id of a Python object, which I retrieved by doing id(thing). How do I find thing again by the id number I was given?

推荐答案

您可能需要考虑以另一种方式实现它.你知道weakref模块吗?

You'll probably want to consider implementing it another way. Are you aware of the weakref module?

(已编辑)Python weakref 模块 可让您保留引用、字典引用和对象的代理,而这些引用不在引用计数器中计数.它们就像符号链接.

(Edited) The Python weakref module lets you keep references, dictionary references, and proxies to objects without having those references count in the reference counter. They're like symbolic links.

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

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