Underscore data hiding (was python development practices?)

John Roth johnroth at ameritech.net
Wed Oct 31 23:58:02 EST 2001


"Skip Montanaro" <skip at pobox.com> wrote in message
news:mailman.1004551677.1783.python-list at python.org...
>
>     Russell> My understanding is that a double underscore is required
for
>     Russell> Python to automagically mangle the name. On the other
hand, two
>     Russell> postings now suggest that a single underscore is
sufficient.
>
>     Russell> If double underscore is required, then it seems to me
this is a
>     Russell> very common misconception that a single is sufficient. It
might
>     Russell> be worth changing.
>
> A double leading underscore is requred to coax Python into mangling an
> attribute.  I think a lot of people use a single underscore as a
simple cue
> for themselves and other programmers that an attribute isn't meant to
be
> part of the public interface without messing up the actual name, so it
can
> be used easily in subclasses.

It also 'hides' the names from a 'from <module> import *' construct.

> --
> Skip Montanaro (skip at pobox.com)
> http://www.mojam.com/
> http://www.musi-cal.com/
>





More information about the Python-list mailing list