"private" variables a.k.a. name mangling (WAS: What is print? A function?)
michele.simionato at gmail.com
michele.simionato at gmail.com
Tue Jan 25 06:32:33 EST 2005
>Name mangling is there to keep you from accidentally hiding such an
>attribute in a subclass, but how often is this really a danger? 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?
Look at the "autosuper" implementation on Guido's descrintro paper;
there the
fact that you user __super instead of _super is essential.
However I have written tens of thousands of lines of Python code and
never
needed __protected variables except in a few experimental scripts for
learning purpose. So I agree that the need does not occur often, but it
is still an useful thing to have.
Michele Simionato
More information about the Python-list
mailing list