Why self?

brueckd at tbye.com brueckd at tbye.com
Wed Jul 10 12:00:19 EDT 2002


On 9 Jul 2002, Robb Shecter wrote:

> And, it according to consensus in this thread, this:
> 
>  >>
> >>   self.y= self.x**2 * self.t/self.z + self.a * FFT(self.tseries)
> >>
> 
> should really be written like this:
> 
> self.__y = self.__x**2 * self.__t/self.__z + self.__a * FFT(self.__tseries)
> 
> to be safe from accidental overwriting by subclasses.

Only in theoretical la-la-land, because in practice that's overkill. When
I first learned about the double-underscore-means-private syntax I adopted
the philosophy of "I'll start to use that everywhere as soon as not using
it gets me into trouble", and that hasn't happened yet. Occasionally I'll
make some variable private, but I've yet to see anything that suggests
doing it most of the time is a best practice.

-Dave






More information about the Python-list mailing list