A java hobbyist programmer learning python

TheFlyingDutchman zzbbaadd at aol.com
Sat Jan 24 13:14:18 CET 2009

On Jan 23, 8:57 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Fri, 23 Jan 2009 01:48:32 -0800 (PST), TheFlyingDutchman
> <zzbba... at aol.com> declaimed the following in comp.lang.python:
> > abstraction. In Python, all class attributes are public but names may
> > be "mangled" to discourage unauthorized access, but otherwise not
> > prevented. It is up to the designer to provide the appropriate
> > interfaces to the data so that the client programmer does not have to
> > resort to manipulating the encapsulated data attributes."
>         Double underscore "mangling" was not implemented to "discourage
> unauthorized access". Its primary purpose is to prevent name space
> conflicts when an extended subclass and its parent class use the same
> name for an attribute, but that attribute is not of the same "meaning".
> Using the __ prefix means BOTH attributes are part of the instance, but
> the subclass only see's its variant and should make calls into
> superclass methods to modify the parent variant.
>         Python convention is that a single underscore -- which does NOT
> perform name mangling -- is the indicator meant to "discourage
> unauthorized access".

Is there a significant performance hit with using the double
underscore for signifying a variable you want to be private? It seems
like it is advantageous that someone trying for direct access has to
use a different notation, which will help to emphasize that it
shouldn't be access directly.

More information about the Python-list mailing list