Printing a variable's name not its value

travislspencer at gmail.com travislspencer at gmail.com
Wed Jul 20 16:01:32 EDT 2005


Bruno Desthuilliers wrote:
> travislspencer at gmail.com a écrit :
> > globals = {}
>
> globals() is a builtin function, you should no shadow it.

Oh, woops.  I'll fix that.

> def printVerbose(*args, **kwargs):
>
> >     if VERBOSE in globals:
> >         for a in args:
> >             if a in globals:
> >                 value = globals[a]
>
>           for k, v in kwargs:
> >             print "%s: %s" % (k, v)
> >

Perfect.  Thanks for the pointer.

> > I've been told on #python that there isn't a way to get a variable's
> > name.  I hope this isn't so.
>
> It is so. In fact, there is nothing like a 'variable' in Python. What we
> have are names bound to objects. Names 'knows' what objects are bound to
> them, but objects knows *nothing* about names they are bound to.

OK.  This seems like it might take some getting used to.  Thanks again
for the help.

--

Regards,

Travis Spencer




More information about the Python-list mailing list