Thread Previous • Date Previous • Date Next • Thread Next |
2008/4/2, Anders Logg <logg@xxxxxxxxx>: > 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 makes it private, which is inaccessible(*) by anyone outside the class, I don't think we have any such variables. Try running this code: class B: def __init__(self): self.a = 1 self._b = 2 self.__c = 3 b = B() print b.a print b._b print b.__c -- Martin
Thread Previous • Date Previous • Date Next • Thread Next |