"Aliasing" an object's __str__ to a different method
Christopher Subich
spam.csubich+block at block.subich.spam.com
Sat Jul 23 20:45:48 EDT 2005
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()).
More information about the Python-list
mailing list