A better self

Max M maxm at mxm.dk
Fri Jul 19 02:51:14 EDT 2002


Erik Max Francis wrote:
> Max M wrote:
>>I don't especially like "self" myself. But wouldn't it be easy enough
>>to
>>just:

> An obvious issue is what happens with respect to bound and unbound
> methods.  The self argument is often implicit in normal work, but it
> _is_ there, and needs to be set up properly.  In your scheme, what
> happens when you write:


Arh bugger. I don't disagree, and I made the typical typo that I often 
do when creating classes.

I forgot to add self as the prameter. So my example should have looked like:

class ProjectScheduler:

     pi = 3.14

     def setEstimatedTime(self, hours):
         self.estimatedTime = hours

     def calculateRealisticTime(self, estimatedTime):
         # rebinding vars to make the calculation easier on the eye
         pi            = self.pi
         estimatedTime = self.estimatedTime
         # the formula
         realisticTime = estimatedTime * pi
         # return result
         return realisticTime

/me slapping himself on forehead repeatedly

regards Max M




More information about the Python-list mailing list