How to get the 'name' of an int
Charl P. Botha
cpbotha at i_triple_e.org
Fri Feb 28 20:52:15 EST 2003
> "Hans Brand" <Hans.Brand at BrandInnovators.com> wrote in message
> news:b3najo$hej$1 at reader08.wxs.nl...
>> Hi,
>>
>> I would like to get the 'name' of a variable to do something like this:
>>
>> causea = 12
>> causeb = 13
>> for cause in (causea, causeb):
>> print "%s = %s" %(name(cause), cause)
To find the name of the variable, you could also try something like:
[i[0] for i in locals().items() if i[1] is causea][0]
which will yield the string 'causea' if you've bound causea as above.
--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/
More information about the Python-list
mailing list