Which way to say 'private'?

Jacek Generowicz jacek.generowicz at cern.ch
Fri Aug 22 06:56:28 EDT 2003


Daniel Klein <danielk at aracnet.com> writes:

> On Thu, 21 Aug 2003 11:42:02 -0400, "Sean Ross"
> <sross at connectmail.carleton.ca> wrote:
> 
> >"Daniel Klein" <danielk at aracnet.com> wrote in message
>
> >Personally, I use single underscore to denote "protected", and double
> >underscore to denote "private" (if I use them at all).

This is not the orthodox convention: single underscore indicates
"privacy" (more accurately: "this isn't part of the interface"):
double underscore is actually a mechanism for avioiding name clashes.

> I should probably have mentioned that I am concerned about advertising the
> 'public' interface (so that users of the class know how best to use it and
> what my intentions were) more than 'restricting' access to 'private' members,
> which we all know is pretty much pointless in Python ;-)

Definitely single underscore. 

(Also, remember that, with properties, you can have things which look
like direct attributes actulally be set and read with setter and
getter functions, so it is perfectly OK to make data attributes be
part of the interface, as you can later install getters and setters
for them without changing the interface.)




More information about the Python-list mailing list