[Zope-dev] Please help - Persistent dictionary keys

John D. Heintz jheintz@isogen.com
Tue, 19 Sep 2000 09:41:57 -0500


Can someone please explain the best way for me to map from one instance
to another?

In the following code either:
(1) I am using dictionaries wrong, or
(2) I'm missing something with ExtensionClass in general.  

I have tried searching Zope and Python mailing lists and resources for
an answer to this question but have become confused by different
conflicting messages.  On the one hand I have heard that dictionary keys
are supposed to be immutable.  On the other, I've heard that
dictionaries are used to simulate (key is object, value is ignored) some
aspects of sets.  Which is correct?  

What I really want is to be able to map a Persistent object to a string
with fast lookup.

Thanks for any help.
John Heintz


import ZODB
from Persistence import Persistent

class Test1:
    pass

class Test2(Persistent):
    pass

dict = {}
t1 = Test1()
t2 = Test2()

try:
    dict[t1] = 1
except:
    print "Using instance of Test1 as key failed!"

try:
    dict[t2] = 2
except:
    print "Using instance of Test2(Persistent) as key failed!"


-- 
John D. Heintz
DataChannel, Inc.
Senior Engineer
512-633-1198
jheintz@isogen.com