Semantics of ==
Isaac To
kkto at csis.hku.hk
Fri Mar 26 01:26:18 EST 2004
>>>>> "Raymond" == Raymond Hettinger <python at rcn.com> writes:
Raymond> [Axel Boldt]
>> > >>> l=[1] > >>> s=l > >>> l.append(s) > >>> w=[1] > >>> r=[1,w] >
>> >>> w.append(r) > >>> s [1, [...]] > >>> w [1, [1, [...]]] > >>>
>> s==w > True
>> >
>> > Note that they're equal, yet are printed differently.
>> >
>> > >>> s[0]=2 > >>> w[0]=2 > >>> s==w > False
>> >
>> > All of a sudden they have become unequal.
Raymond> [John Roth]
>> You've got a recursive structure! I originally thought that the [...]
>> was something you'd done to the printout, but it isn't.
>>
>> I think the original True is a bug. It's getting confused by the
>> recursion.
Raymond> Armin Rigo found and fixed this for Py2.4:
Raymond> Python 2.4a0 (#46, Mar 23 2004, 01:55:44) [MSC v.1200 32 bit
Raymond> (Intel)] on win32 <snipped>
>>>> s
Raymond> [1, [...]]
>>>> w
Raymond> [1, [1, [...]]]
>>>> s==w
Raymond> Traceback (most recent call last): File "<pyshell#9>", line 1,
Raymond> in -toplevel- s==w RuntimeError: maximum recursion depth
Raymond> exceeded in cmp
I'm confused... what makes the new behaviour more "correct" than the original?
Regards,
Isaac.
More information about the Python-list
mailing list