Different Random Numbers Between Already/Not Yet Compiled Code

Tim Peters tim.one at home.com
Thu Jan 24 16:57:40 EST 2002


[Eric Eide, reveals <wink> that he's using keys that are instances
 of a class that doesn't define __cmp__, but is sorting dict.items()
 now]

]Tim]
> A good solution -- unless you're merely sorting by the keys'
> memory addresses (and then this problem will come up
> again, sooner or later).

[Eric]
> No, at least I knew not to do that :-).

[Jason Orendorff]
> Unless you've defined __cmp__() that's what you're doing.  :-)

Exactly -- but Python won't *let* you use instances as dict keys unless you
define both or neither of

1. __hash__
2. One of {__cmp__, __eq__}

Since Eric said he doesn't define __hash__, but is using these guys as dict
keys, that implies he isn't defining __cmp__ (or __eq__) either.  So if he's
using the default .sort(), he is sorting by memory address.  It's possible
that he's using a custom sort function, though.

Eric, show us some code instead of trying to describe what you're doing.
It's Python code:  it's easier to read than to describe <wink>.





More information about the Python-list mailing list