Private methods

Ramchandra Apte maniandram01 at gmail.com
Wed Oct 10 11:56:57 EDT 2012


On Wednesday, 10 October 2012 18:38:04 UTC+5:30, Roy Smith  wrote:
> In article 
> 
> <1krpdak.u0qy9e1a4knspN%real-not-anti-spam-address at apple-juice.co.uk>,
> 
>  real-not-anti-spam-address at apple-juice.co.uk (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.
> 
> > 
> 
> > 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?
> 
> 
> 
> Yes (modulo some details of how import works that I've never fully 
> 
> figured out and which lack of knowledge hasn't seemed to have hurt me 
> 
> any).
> 
> 
> 
> I view public and private in Python this way:
> 
> 
> 
> Public: I hereby declare that this method or attribute is part of the 
> 
> promised never to change interface of this class.  I might possibly 
> 
> break that promise at some point in the future, but if I do, you have 
> 
> the right to bitch and whine about it, and I'm morally obligated to at 
> 
> least pretend I care.
> 
> 
> 
> Private: I hereby declare that this method or attribute is something I 
> 
> needed to have for my own purposes, and is officially hidden inside my 
> 
> kimono.  Like all things inside my kimono, you may speculate about their 
> 
> existence all you want, but you touch them at your own peril.  I may 
> 
> change them at some point in the future, and while you can bitch and 
> 
> whine about it all you want, I'm not listening.

Uhum. Language please.



More information about the Python-list mailing list