Private methods

Robert Kern robert.kern at gmail.com
Tue Oct 9 10:12:47 EDT 2012


On 10/9/12 2:59 PM, D.M. Procida wrote:
> Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>
>> On 09/10/2012 14:24, D.M. Procida wrote:
>>> What exactly is the point of a private method? Why or when would I want
>>> to use one?
>>>
>>> Daniele
>>>
>>
>> Hardly a Python question but using a search engine could have got you
>> here, and rather faster :)
>>
> http://stackoverflow.com/questions/2620699/why-private-methods-in-the-ob
> ject-oriented
>
> Thanks. Sometimes I prefer to talk to real people on Usenet than do web
> searches. Just my preference.

That's understandable, but the real people on Usenet who will answer your 
questions usually prefer that you do a web search first, for a variety of reasons.

   http://www.catb.org/esr/faqs/smart-questions.html#before

> Anyway, one of the answers on that page explains that public methods are
> interfaces to a class, that other things might rely on, and private ones
> are for its own internal logic, that other things don't need to care
> about.
>
> In Python, using an underscore is simply a convention to note that a
> method is private - it doesn't actually hide it from other things -
> correct?

This is correct.

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