recursion in __cmp__

Victor Safronovich vsafronovich at naumen.ru
Fri Nov 5 09:45:28 CET 2004


please comment this
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
>>> class A:
        def __cmp__(self, other):
                print '%s|%s' %(`self`, `other`)
                return cmp(self, other)

>>> a = A()
>>> cmp(a,A())
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
<__main__.A instance at 0x00989838>|<__main__.A instance at 0x0097D120>
0
>>> cmp(a,5)
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
<__main__.A instance at 0x00989838>|5
0



More information about the Python-list mailing list