May-15-2021, 12:09 AM
Not directly. The object itself doesn't have knowledge of other objects that may refer to it. It may in fact be "in" tons of other objects, so it could simultaneously be in both lists and tuples. It might be "in" an object that is no longer referenced and will be garbage-collected away later.
Cpython internals have a reference count, but I'm not sure how you could access that. Even with the count, I don't think you can manipulate it to get the objects holding the reference.
You could potentially inspect all objects in your current scopes and examine them all of their contents looking for your target object, but I would look for other ways to solve the problem before attempting. How are you trying to use this information?
Cpython internals have a reference count, but I'm not sure how you could access that. Even with the count, I don't think you can manipulate it to get the objects holding the reference.
You could potentially inspect all objects in your current scopes and examine them all of their contents looking for your target object, but I would look for other ways to solve the problem before attempting. How are you trying to use this information?