Finding the instance reference of an object

Aaron "Castironpi" Brady castironpi at gmail.com
Thu Oct 16 20:51:43 CEST 2008


On Oct 16, 12:25 pm, Astley Le Jasper <Astley.lejas... at gmail.com>
wrote:
> Thanks for all the responses. That helps.
>
> Ta
>
> ALJ

If you're sure it's unique, why not just scan through the pairs in
locals()?

for k, v in locals():
  if v is the_object_im_looking_for:
    name_im_looking_for= k

This method can sometimes return more than one name, due to the
variable ordering of objects in dictionaries.



More information about the Python-list mailing list