Underscore data hiding (was python development practices?)

Peter Wang pzw1
Wed Oct 31 17:59:55 EST 2001


On Wed, 31 Oct 2001 12:05:11 -0600, Skip Montanaro <skip at pobox.com>
wrote:

>
>    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.

heh... so:

C++::private == Python."__*"
C++::protected == Python."_[a-zA-Z]*"
C++::public == Python."[a-zA-Z]*"

;)

-peter



More information about the Python-list mailing list