Q: names with underscores and style

Barry A. Warsaw bwarsaw at cnri.reston.va.us
Tue Aug 3 22:45:17 EDT 1999


>>>>> "TAB" == Thomas A Bryan <tbryan at arlut.utexas.edu> writes:

    TAB> Basically, I'm trying to figure out when to use a leading 
    TAB> underscore for a method/member name.  Is there some rule of
    TAB> thumb for underscores in Python names?

Attributes with DLUNTU (double leading underscore, no trailing
underscores) are treated as private attributes, and Python munges
their names.  E.g. self.__privatemeth()  Use these when you definitely 
don't want subclasses to access or override them (Python doesn't
actually /enforce/ any access control -- remember we're all consenting 
adults :).

My own personal convention is to use SLUNTU (single leading ...) when
I want attributes that are part of the `protected' interface of a
class.  E.g. self._override_this()

DLUDTU (double leading ... double trailing), e.g. self.__init__() are
reserved for Python's use.

-Barry




More information about the Python-list mailing list