change of random state when pyc created??

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Thu May 10 01:34:48 EDT 2007


On Wed, 09 May 2007 23:10:19 -0500, Robert Kern wrote:

> Steven D'Aprano wrote:
>> On Wed, 09 May 2007 21:18:25 -0500, Robert Kern wrote:
>> 
>>> Actually, the root cause of Peter's specific example is the fact that the
>>> default implementation of __hash__() and __eq__() rely on identity comparisons.
>>> Two separate invocations of the same script give different objects by identity
>>> and thus the "history of insertions and deletions" is different.
>> 
>> The history is the same. The objects inserted are the same (by equality).
> 
> No, they *were* different by equality (identity being the default implementation
> equality that was not overridden in either Peter's code nor Alan's).

Ah yes, you are right in the sense that Python's notion of equality for
class instances is to fall back on identity by default.

But in the vernacular human sense, an instance X with the same state as an
instance Y is "equal", despite being at another memory address. I was
using equality in the sense that two copies of the same edition of a book
are the same, despite being in different places.

For the record, and for the avoidance of all confusion, I'm not suggesting
that Python's default behaviour is "wrong" or even "bad", merely pointing
out to all those wise in hindsight that the behaviour was extremely
puzzling for the reasons I've given. But you can be sure that I'll never
forget this lesson :)



-- 
Steven.




More information about the Python-list mailing list