recursion in __cmp__
Alex Martelli
aleaxit at yahoo.com
Fri Nov 5 04:43:49 EST 2004
Victor Safronovich <vsafronovich at naumen.ru> wrote:
> 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)
What is there to comment? This is obviously and blatantly recursive,
since cmp(a, b) delegates back to a.__cmp__(b) [[for classic classes;
for a newstyle class it would be type(a).__cmp__(a, b) with the same
recursive effect in this case]].
Just like the simpler example: def __len__(self): return len(self)
Alex
More information about the Python-list
mailing list