|
|
|
|
|
by masklinn
3187 days ago
|
|
> that's "really really don't touch this". That's not. The use case for name mangling was "avoid the risk of conflict when designing classes for inheritance": if you're building classes for inheritance, subclasses using the same name for an internal/private attribute are not going to unwittingly collide with the base classe's. |
|
A single underscore is something that's not part of the classes public API, any child classes may need to change attributes, and by using a double underscore you are saying "I know better than you, you won't ever need to change this", which is never true.
Python isn't like Java where you often have complex and often convoluted class heirachies, where truly private attributes might be more useful.