B
Bruno Desthuilliers
Maciej Bliziński a écrit :
(snip the rest - already answered by at least 3 persons).
First, keep in mind that that Python *does not* have any notion of
(languaged enforced) access restriction. All that the __name thingie
does is to mangle the name with the class name, so A.bar become
A._A__bar. This can be useful. Sometimes. Perhaps. (FWIW, I think I've
used it once in seven years and I'm not sure it was really necessary
after all).
Now there's a strong convention which says that _names prefixed by a
single underscore are implementation stuff, and that anyone messing with
implementation stuff implicitely accepts all the possible consequences.
(snip the rest - already answered by at least 3 persons).
I
don't want to expose the __bar() function outside, but on the other
hand i want to defer its implementation to a subclass. It seems like I
need to make it public, doesn't it?
First, keep in mind that that Python *does not* have any notion of
(languaged enforced) access restriction. All that the __name thingie
does is to mangle the name with the class name, so A.bar become
A._A__bar. This can be useful. Sometimes. Perhaps. (FWIW, I think I've
used it once in seven years and I'm not sure it was really necessary
after all).
Now there's a strong convention which says that _names prefixed by a
single underscore are implementation stuff, and that anyone messing with
implementation stuff implicitely accepts all the possible consequences.