>>> for i in dir():
>>>      if eval(i) == Banana:
>>>              print i
>> (sound of head hitting desk)
>>
>> </F>
>>
> lol

As freakish as the solution was, it's not too far off from 
something that actually works (mostly, kinda sorta):

 >>> banana = {}
 >>> spatula = banana
 >>> propane = {}
 >>> [name for name in dir() if id(eval(name)) == id(banana)]
['banana', 'spatula']
 >>> dir()
['__builtins__', '__doc__', '__name__', 'banana', 'name', 
'propane', 'spatula']

While the original just compared on value (and thus, with the 
original "solution", "propane" would also be found), it should be 
pretty safe to compare on id() equality.

Okay, it's semi-obcene in my book, but it's an actual solution in 
a way.

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to