{Spam?} Re: [Tutor] How to get variable name from its id()
Bob Gailer
bgailer at alum.rpi.edu
Fri Feb 6 21:23:11 EST 2004
>Em Fri, 6 Feb 2004 02:07:57 -0500, "Isr Gish" <isrgish at fusemail.com>
>atirou este peixe aos pinguins:
>
>Is it possible to get the variable name or its contents if we know its I'd.
> >
>Name = 'Isr Gish'
>ID = id(Name)
>Now use ID to either find the variable name (Name), or get the contents of
>Name.
>
>If someone can point me where to find this info. It would be greatly
>appreciated.
After assigning some variables, run this code:
for key, value in globals().items(): print key, value, id(value)
Each line of output is one variable name, its contents, and its id. There
is a lot of builtin stuff, but amongst it are the entries you created.
Add a little search logic to compare each id to the desired one and you
have your answer.
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell
-------------- next part --------------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.577 / Virus Database: 366 - Release Date: 2/3/2004
More information about the Tutor
mailing list