Will python never intend to support private, protected and public?

Mike Meyer mwm at mired.org
Fri Sep 30 20:05:44 EDT 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> OTOH, "private" lets you say 100% for certain that another class
> didn't clobber __xyz, and that any bug that clobbered it MUST reside
> in the class that declared it.  That makes auditing for __xyz-related
> errors a lot simpler since you only have to look in one class for them.

Horse pucky.

>>> class Fools(object):
...     _bar = "my private list of values".split()
...     def broken(self, breaker):
...         breaker(self._bar)
... 
>>> class Kings(object):
[Elided, because you said you don't need it.]
>>> fool = Fools()
>>> king = Kings()
>>> fool.broken(king.get_victim)
>>> king.breakit()
>>> fool._bar
[]
>>> 

So, fool._bar is now clobbered. Nuts, the _bar attribute is broken for
*every* instance of Fools. According to you, the error must be in
Fools. Care to point it out?

       <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list