Getting the name of an instance

Tal Linzen pachy at 012.net.il
Wed Jan 16 16:13:51 EST 2002


Hi.

Suppose I have:
p = MyClass()

I'm looking for a function that works like:
func(p) = 'p'
(meaning, retrieves the actual name of the variable).

The best I could come up with is:
def func(p):
    return globals().keys()[globals().values().index(p)]

Surely there's a simpler way, something like the __name__
method in module objects.





More information about the Python-list mailing list