Q: Subclassing dict and __cmp__
Miki Tebeka
tebeka at cs.bgu.ac.il
Sun Oct 20 02:40:14 EDT 2002
Hello All,
Can anyone explain the following? (or point me to a link since my
googleing didn't help this time :)
--------------
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license" for more information.
IDLE Fork 0.8 -- press F1 for help
>>> class H(dict):
def __cmp__(self, other):
'''Compare only x's'''
if self['x'] == other['x']:
return 0
return 1
>>> h1 = H()
>>> h1
{}
>>> h2 = H()
>>> h2
{}
>>> h1 == h2
1
>>>
------------------
Thanks.
Miki.
More information about the Python-list
mailing list