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

Richie Hindle richie at entrian.com
Tue Jan 25 07:40:49 EST 2005


[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 at entrian.com




More information about the Python-list mailing list