Private methods

Robert Kern robert.kern at gmail.com
Wed Oct 10 08:47:57 EDT 2012


On 10/10/12 12:51 AM, Steven D'Aprano wrote:
> On Tue, 09 Oct 2012 11:08:13 -0600, Ian Kelly wrote:
>
>> On Tue, Oct 9, 2012 at 8:08 AM, Demian Brecht <demianbrecht at gmail.com>
>> wrote:
>>> A single underscore semantically means private. A double underscore
>>> will name mangle the function such that it's only accessible strictly
>>> by name through the class that it's define in. Note that you *can*
>>> still access it if you understand how name mangling works. Nothing in
>>> Python is truly private.
>>
>> I tend to view name mangling as being more for avoiding internal
>> attribute collisions in complex inheritance structures than for
>> designating names as private.
>
> Really? I tend to view name mangling as a waste of time, and complex
> inheritance structures as something to avoid.

Whatever you may think of the use case, it was the motivating reason why it was 
put into the language:

http://docs.python.org/reference/lexical_analysis.html#reserved-classes-of-identifiers

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list