How to get the 'name' of an int

Hans Brand Hans.Brand at BrandInnovators.com
Fri Feb 28 05:15:18 EST 2003


"Rene Pijlman" <reageer.in at de.nieuwsgroep> wrote in message
news:0hcu5v88fg2gvr52hvnlkr8hio3kfqefa9 at 4ax.com...
> Hans Brand:
> >I would like to get the 'name' of a variable to do something like this:
>
> That's not possible, 0 or more names map to 1 object, there is
> no reverse mapping (AFAIK). But...
>
> >causea = 12
> >causeb = 13
> >for cause in (causea, causeb):
> >    print "%s = %s" %(name(cause), cause)
> >
> >The result should be:
> >causea = 12
> >causeb = 13
> >
> >How can I achieve this?
>
> it can be done like this:
>
> causea = 1
> causeb = 2
> for cause in ("causea", "causeb"):
>     print "%s = %d" % (cause, eval(cause))
>
I can work with this solution! Bedankt!

> And you could add some code to read the set of variables from a
> namespace, instead of hardcoding it.
>
> --
> René Pijlman
>
> Wat wil jij leren?  http://www.leren.nl






More information about the Python-list mailing list