A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-March/021859.html below:

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

[Python-Dev] repr(x) != x.__repr__() [Python-Dev] repr(x) != x.__repr__()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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4