[Zope-dev] Test(Persistent) failing with AttributeError: __hash__
John D. Heintz
jheintz@isogen.com
Wed, 06 Sep 2000 18:11:29 -0500
In the following code either I am using dictionaries wrong or I'm
missing something with ExtensionClass in general. Can someone explain
the best way for me to map from one instance to another?
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.
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