how do you get the name of a dictionary?

Andy Terrel andy.terrel at gmail.com
Fri Aug 18 17:32:54 EDT 2006


Why bang your head?  It was a stupid hack that has lots of problems,
but done in a way that is readable.  Sure I could do something more
functional or one lined like:

Banana={}
names = filter(lambda x:id(eval(x))==id(Banana),dir())

but I am guessing that it is harder to read by many.  Anywho I can
think of plenty of reasons it would fail, but it really depends on the
app.


Fredrik Lundh wrote:
> Andy Terrel wrote:
>
> > for i in dir():
> >      if eval(i) == Banana:
> >              print i
> 
> (sound of head hitting desk)
> 
> </F>




More information about the Python-list mailing list