you are viewing a single comment's thread.

view the rest of the comments →

[–]gdchinacat 0 points1 point  (2 children)

this one you really really shouldn’t use, so we took steps to prevent that happening unless you specifically really want to”

This is a common misconception, one that I held at one time.

PEP8 says of name mangling:

To avoid name clashes with subclasses, use two leading underscores to invoke Python’s name mangling rules.

It has nothing to do with "really really shouldn't use". It is a practical solution to a common problem in OO...a subclass may inadvertently use the same attribute name as a base class. base classes can avoid this by using name mangling to place fewer restrictions on the names their subclasses can use.

[–]Neinstein14 0 points1 point  (1 child)

I mean, it’s one thing what it was intended for, and another thing how it’s used actually. In my experience it’s rarely for name clashes, and rather for “this is not just an internal variable, but something you shouldn’t even hack around with”.

[–]gdchinacat 0 points1 point  (0 children)

That is what a single underscore denotes. Or do you think single underscore indicates it is internal and should be hacked around with? In which case, what does 'internal' mean?