← Back to team overview

ufl team mailing list archive

Re: Variable name style choice

 

Anders Logg wrote:
On Wed, Apr 02, 2008 at 12:27:45PM +0200, Martin Sandve Alnæs wrote:
In Python, variables are made private or protected in an "informal
way" by prefixing their names with __ or _. Some places I've used
self._foo instead of self.foo for variables which the end-user (person
inputting a form) shouldn't touch, do you agree with this? Most of
these are variables the form compiler developers will be dealing with.
I haven't been completely consistent, so I just want green light
before I change these one way or the other.

Agree, but shouldn't it be two underscores?

Two underscores are reserved for Python private names and there
is some magic effects with class attributes that have two underscores
as prefix (this is actually the way to get some protection to attribute values). Authors of Python packages should use one underscore for private names, in general.

Pearu


Follow ups

References