"private" variables a.k.a. name mangling (WAS: What is print? A function?)
Philippe C. Martin
philippecmartin at sbcglobal.net
Tue Jan 25 09:55:16 EST 2005
Well I _was_ a bit slow on that one !
So I will happily stick to the double underscore.
Regards,
Philippe
Le mardi 25 janvier 2005 à 10:28 +0000, Simon Brunning a écrit :
> On Mon, 24 Jan 2005 12:17:13 -0600, Philippe C. Martin
> <philippecmartin at sbcglobal.net> wrote:
> >
> > I use "__"for private variables because I must have read on net it was
> > the way to do so - yet this seems to have changed - thanks:
> >
> > http://www.network-theory.co.uk/docs/pytut/tut_77.html
>
> Nope, that's still the right way to make a member 'really' private.
> Stephen was pointing out a very common Python idiom - "private by
> convention", and suggesting that using it would be more appropriate.
>
> A member with a single preceding underscore is private by convention.
> That is to say, there is no mechanism in place to prevent clients of
> the class accessing these members, but they should consider themselves
> to have been warned that they do so at their own risk.
>
> If you take the back off the radio, the warranty is void. ;-)
>
> I (and by inference Stephen) feel that this is a more "Pythonic"
> approach. Give the programmer the information that they need, but
> don't try to stop them from doing what they need to do.
>
--
***************************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***************************
More information about the Python-list
mailing list