A better self
Terry Reedy
tjreedy at udel.edu
Thu Jul 11 22:12:54 EDT 2002
"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
news:slrnairg48.c4b.huaiyu at gauss.almadan.ibm.com...
> What is required is a convention that allows shorter notions when
necessary
> in a disciplined way. I find that switching from self to _ is quite
> satisfactory for this purpose under the right circumstances. And,
as such,
> there is no need to extend Python's syntax for this purpose, which
was the
> initial topic of this thread.
Another alternative is to copy instance vars to local vars and then
use the latter without the 'self.' or 'self.__' prefix. If there
are multiple references to the instance vars within a method, this may
be just as fast or faster. IE
def quadsolve(self):
a,b,c = self.a, self.b, self.c
discrim = b*b - a*c
...
Terry J. Reedy
More information about the Python-list
mailing list