Retrieving a variable's name.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Aug 21 05:32:17 CEST 2007


On 20 ago, 22:03, rodrigo <rodrigo... at gmail.com> wrote:

> How would I go about retrieving a variable's name (not its value)? I
> want to write a function that, given a list of variables, returns  a
> string with each variable's name and its value, like:
>
> a: 100
> b: 200
>
> I get the feeling this is trivial, but I have been unable to find an
> answer on my own.

Try using dir(), dir(xxx), vars(), vars(xxx), locals(), globals()
<http://docs.python.org/lib/built-in-funcs.html>

--
Gabriel Genellina




More information about the Python-list mailing list