Proposal for removing self
Max M
maxm at mxm.dk
Thu Aug 26 09:03:03 EDT 2004
Brent W. Hughes wrote:
> When doing object-oriented stuff, it bothers me to have to type "self" so
> many times. I propose that Python allow the programmer to optionally type
> ".variable" instead of "self.variable" to mean the same thing. Of course,
> the interpreter would have to be more careful about detecting floats that
> begin with just a period as in ".5". What are your thoughts?
You don't have to use self. You could simply use underscore '_' instead.
class Person:
def setName(_, name):
_.name = name
def getName(_):
return _.name
But other Python programmers will hate you for it ;-)
If it is because you are using an attribute too many times inside a
method, a better solution is to map it to a local variable. It also has
the advantage of being faster.
class SoftwareProjectEstimator:
pi = 3.14
def guestimatePrice(self, hours, hour_price, developer_group_size):
pi = self.pi
guess = hours * pi
guess *= pi * developer_group_size
return guess * hour_price
regards Max M
More information about the Python-list
mailing list