News for hackers. Stuff that matters.
Re:Python Oddities by masklinn on Tuesday August 08, 2017 @08:24AM (#14957040)
Within class bodies, symbols prefixed with two underscores get "mangled" (prefixed with the class name).

This is intended to avoid risks of collisions for classes built specifically for inheritance so you'd usually use it with attributes e.g. `self.__name = name` (that way if a subclass defines its own "name" things will work as expected for both). I was unaware this also worked for straight local variables.

I was unaware it happened for all symbols, but I guess it makes sense as the Python compiler does very little analysis.

There are no comments on this comment yet.