This is an old copy of the Python FAQ. The information here may be outdated.

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

 

A Django site. rendered by a django application. hosted by webfaction.