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: Paolino <paolo_veronelli@tiscali.it>
Date: Sat Jul 23 2005 - 12:27:31 CEST

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
Received on Thu Sep 29 17:07:22 2005