Re: "Aliasing" an object's __str__ to a different method
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: "Aliasing" an object's __str__ to a different method

From: Christopher Subich <spam.csubich+block@block.subich.spam.com>
Date: Sun Jul 24 2005 - 02:45:48 CEST

Paolino wrote:
> Little less ugly:
> In [12]:class A(object):
> ....: def __str__(self):return self.__str__()
> ....: def str(self):return 'ciao'
> ....: def setStr(self):self.__str__=self.str
> ....:
>
> In [13]:a=A()
>
> In [14]:a.setStr()
>
> In [15]:str(a)
> Out[15]:'ciao'

Not quite bug-free, by my eye that'll infintely recur if you call str(A()).
Received on Thu Sep 29 17:07:55 2005