Getting the name of an instance
Jason Orendorff
jason at jorendorff.com
Wed Jan 16 16:19:53 EST 2002
> 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.
Nope. Variables have names, but most values don't have names
in Python.
Anyway, what would func(13) return?
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list