0

Python's id() returns the identity of an object as an integer.

Is there a Python function that does the compliment of that? That is, a function X() such that:

class ABC(object): pass
a = ABC()
b = X(id(a))
assert b is a
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
JimB
  • 971
  • 8
  • 20
  • This might help: [Is it possible to dereference variable id's?](https://stackoverflow.com/questions/15011674/is-it-possible-to-dereference-variable-ids) – sj95126 Jul 22 '21 at 15:37
  • 2
    If all you have is the `id` of an object, rather than an actual reference to it - the object could very well have been garbage-collected, so if your hypothetical `X()` function returned anything at all, there would be no guarantee that it was the original object. – jasonharper Jul 22 '21 at 15:40

0 Answers0