Magic?

mk mrkafk at gmail.com
Sun Jul 13 18:55:11 CEST 2008


> However, it appears that somehow this object prints the value of 's' 
> attribute without me setting any specific methods to do that:
> 
>  >>> astr = lstr('abcdef')
>  >>> astr
> 'abcdef'
>  >>> astr.swapcase()
> 'ABCDEF'

Correction: it doesn't really get the value from _s attribute:

 >>> astr = lstr('abcdef')
 >>> astr.s
'abcdef'
 >>> astr.s='xyzzy'
 >>> astr
'abcdef'
 >>> astr.s
'xyzzy'


So my updated question is where does this lstr() instance keep the 
original value ('abcdef')? It obviously has smth to do with inheriting 
after str class, but I don't get the details of the mechanism.




More information about the Python-list mailing list