Underscore data hiding (was python development practices?)

Russell E. Owen owen at astrono.junkwashington.emu
Thu Nov 1 11:40:44 EST 2001


In article <9rq2v2$fko$1 at newshost.accu.uu.nl>,
 m.faassen at vet.uu.nl (Martijn Faassen) wrote:

>The double underscore is required for name mangling, but I don't really
>like the name mangling; it gets in the way. I just want to give the 
>programmer a hint that some attribute is private, and I use a single
>underscore for this, and many Python programmers with me.
>
>Why does name mangling get in my way? Generally I like to be able to
>reach the private variables in subclasses (I suppose this makes them
>protected in C++ terms, though my C++ is rusty). I also like being
>able to fake things easily in case I need it, for debugging and
>testing purposes. In the end I only want to indicate something is private
>without all the hassle of name mangling.

Personally, I prefer the effect of double underscore for this case, as 
well. I can easily get to the variables by applying the name mangling 
myself, yet cannot accidentally stomp on the variables in a subclass.

To each his/her own.

-- Russell



More information about the Python-list mailing list