Re: How to print the name of a list?



In general, no --- there is no unique mapping between references and
names.

For debugging, however, it is sometimes useful to try this kind of
reverse lookup by iterating over the global dictionary:

def guess_name(thing):
for name, reference in globals.iteritems():
if thing is reference:
return name
else:
return None

# example use:

foo = [1, 2, 3]
bar = [4, 5, 6]
baz = [foo, bar]

for thing in baz:
print guess_name(thing)

# prints "foo" and "bar"


I should emphasize that this is NOT failsafe, and it shouldn't be used
in any way except for debugging IMHO. If you need to associate names
with objects in a guaranteed way, use a dictionary.

.



Relevant Pages

  • Re: Tcl escape characteres
    ... Debugging, I found that the parameters given to spawn by tcl engine ... % lappend cmd foo bar $ssh_password baz ...
    (comp.lang.tcl)
  • Re: debug class library
    ... I have the Debug mode set as "Program" and Start Application set as the exe ... that references this dll. ... I tried attaching 2 screen shots, one showing the debugging settings and the ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Text Box or String > 32K -- Problem?
    ... lengths on various fields and objects while debugging the code. ... individual routines out of the module. ... to my References in VBA. ... Marshall Barton wrote: ...
    (microsoft.public.access.formscoding)
  • BUG: debugger is case-sensitive to paths when resolving assembly refrences
    ... DotNet has always had quirky problems with debugging DLL's when running ... breakpoints (question marks), or break points that get a "plus" sign next to ... if one project references an ... treat these two references as *different* assemblies. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How can two references to the same object behave differently?
    ... Burt in another post on this thread, is that foo.bar = baz is invoking a ... Also it's important to note that Ruby's object references are different from C++ references. ...
    (comp.lang.ruby)