how can I get the name of a variable (or other object)?
grante at visi.com
Thu Jul 22 18:24:03 CEST 2004
On 2004-07-22, Richard Oudkerk <oudkerk at ma.man.ac.uk> wrote:
> def printvars(varlist):
> allvars = globals()
> for var in varlist:
> print [ n for n in allvars if allvars[n] is var ], "=>", var
I don't think the allvars.update(locals()) is doing anything
useful. The locals it's adding are those belonging to
'printvars' and what one would probably want is the locals
belonging to the caller of printvar.
I like your solution of passing objects better than mine of
passing the name.
Grant Edwards grante Yow! HUGH BEAUMONT died
at in 1982!!
More information about the Python-list