[Python-Dev] repr(x) != x.repr() (original) (raw)

Patrick K. O'Brien pobrien@orbtech.com
Thu, 28 Mar 2002 09:46:51 -0600


[Oren Tirosh]

This phenomenon is not really specific to repr(). It occurs with new-style classes when methods are assigned. Example: class A(object): def repr(self): return 'abc' >>>a = A() >>>a.repr = lambda: 'abc' >>>repr(a) 'abc' >>>a.repr() '123'

You've got a typo in there. Here is the fixed version:

class A(object): ... def repr(self): ... return 'abc' ...
a = A() a.repr = lambda: '123' repr(a) 'abc' a.repr() '123'

Of course, the odd behavior is still there.


Patrick K. O'Brien Orbtech