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. this page was rendered by a django application in 0.00s 2012-02-13 16:55:15.399949. hosted by webfaction.