"self" - a python wart or "feature"

Max M maxm at mxm.dk
Mon Feb 17 11:12:29 CET 2003


Bengt Richter wrote:

> In your example, you don't explicitly use self, so it seems useless.
> Try writing an example that sets instance attributes and uses class
> variables and also makes use of temporary local variables in a method.


Well it works in JavaScript. So it is really a bad example. The self 
could be implicit in any function.

def someFunc(x,y)
     self.x = self.x + x
     return self.x * y

The real problem is because Python can have unbound methods. Which is 
like class members, only outside a class. Then you would need a self 
parameter, and it would get messy.


-- 

hilsen/regards Max M Rasmussen, Denmark

http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme





More information about the Python-list mailing list