Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

From: Richie Hindle (richie_at_entrian.com)
Date: 01/25/05


To: python-list@python.org
Date: Tue, 25 Jan 2005 12:40:49 +0000


[Steven]
> Can someone give me an example of where __-mangling really solved a problem
> for them, where a simple leading underscore wouldn't have solved the
> same problem?

http://cvs.sourceforge.net/viewcvs.py/spambayes/spambayes/spambayes/Dibbler.py?r1=1.13&r2=1.13.4.1

That's a bugfix to SpamBayes, where I'd inadvertently named an instance
variable '_map' without realising that the base class
(asynchat.async_chat) also had an instance variable of that name. Using
double underscores fixed it, and had I used them from the beginning the
bug would never have cropped up (even if asynchat.async_chat had an
instance variable named '__map', which is the whole point (which you know,
Steven, but others might not)).

-- 
Richie Hindle
richie@entrian.com