Why self?

Greg Ewing see_reply_address at something.invalid
Tue Jul 16 22:01:59 EDT 2002


Fernando Pérez wrote:

> 
> wrong. The interpreter mangles the __names automagically by adding the class 
> name. You can work around it, but at least it helps to prevent accidents.


I think it's worth pointing out that the __ mangling is
not intended to make the attribute inaccessible in some
sort of bondage-and-discipline way, but to prevent
name clashes between instance variables in superclasses
and subclasses.

In that respect, it's a considerable improvement over
C++'s "private", which does exactly the opposite -- it
renders things inaccessible *without* doing anything
to prevent clashes!

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list