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

Paolino paolo_veronelli at tiscali.it
Sat Jul 23 06:27:31 EDT 2005


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'

The point is str(ob) builtin looks like calling 
ob.__class__.__str__(ob).Prolly Python-dev is the good place to ask about.



	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it



More information about the Python-list mailing list