We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

I try to use __spam and I get an error about _ClassName__spam.

Variables with a double leading underscore are “mangled” to provide a simple but effective way to define class private variables. Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with any leading underscores stripped.

This doesn’t guarantee privacy: an outside user can still deliberately access the “_classname__spam” attribute, and private values are visible in the object’s __dict__. Many Python programmers never bother to use private variable names at all.

CATEGORY: programming