How to get the 'name' of an int
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Feb 28 13:01:11 EST 2003
Hans Brand wrote:
> "Rene Pijlman" <reageer.in at de.nieuwsgroep> wrote:
>>Hans Brand:
>>>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)
>>
>>causea = 1
>>causeb = 2
>>for cause in ("causea", "causeb"):
>> print "%s = %d" % (cause, eval(cause))
>
> I can work with this solution! Bedankt!
If you liked that, try:
causea = 1
causeb = 2
for name in "causea causeb".split():
print "%s = %d" % (name, eval(name))
or even:
...
dictionary = globals() # or locals() if that is where they are defined
for name in "causea causeb".split():
print "%s = %d" % (name, dictionary[name])
-Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list