Rich comparison methods don't work in sets?
tjreedy at udel.edu
Sun Jun 21 01:22:59 CEST 2009
Gustavo Narea wrote:
> Hello again, everybody.
> Thank you very much for your responses. You guessed right, I didn't
> use the __hash__ method (and I forgot to mention that, sorry).
> And unfortunately, I think I can't make them hashable, because the
> objects are compared based on their attributes, which are in turn
> other kind of objects compared based on other attributes. All these
> class instances are compared with __eq__/__ne__ and they wrap
> relatively complex data which would be hard to attempt to represent
> them unambiguously using a 32-bit integer. That's why I'm afraid I
> cannot use hashables.
If the result of 'o1 == o2' changes over time, then the objects are not
very suitable as set members.
> I guess I'll have to use something like the function of my first
> post. :(
> - Gustavo.
More information about the Python-list