About classes and OOP in Python

bruno at modulix onurb at xiludom.gro
Tue Apr 11 05:15:23 EDT 2006


Roy Smith wrote:
(snip)

> That being said, you can indeed have private data in Python.  Just prefix 
> your variable names with two underscores (i.e. __foo), and they effectively 
> become private.  

The double-leading-underscore stuff has nothing to do with "privacy".
It's meant to protect from *accidental* overriding of implementation stuff.

(snip)

> Yes, that is is a risk.  Most people deal with that risk by doing a lot of 
> testing (which you should be doing anyway).  If you really want to, you can 
> use the __slots__ technique to prevent this particular bug from happening 
> (although the purists will tell you that this is not what __slots__ was 
> designed for).

Ok, so I must be a purist !-)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list