Created
December 16, 2010 19:06
-
-
Save kevinw/743808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nameof(obj): | |
''' | |
if obj is referenced strongly in another object's __dict__, give its attribute name. | |
''' | |
for r in gc.get_referrers(obj): | |
for r2 in gc.get_referrers(r): | |
if r is getattr(r2, '__dict__', object()): | |
for k, v in r.iteritems(): | |
if v is obj: | |
return '[%r attribute of %r]' % (k, r2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment