Use empty string for self

James Stroud jstroud at ucla.edu
Wed Mar 1 01:06:15 EST 2006


John Salerno wrote:
> Grant Edwards wrote:
> 
>>> A related thing I was wondering about was the use of 'self' in
>>> class methods as the first parameter.
>>
>>
>> It's not a related thing, it's the same thing.
> 
> 
> Oh sorry. I thought the OP was asking about having to use self when 
> qualifying attributes, or even if he was, I didn't realize it was the 
> same principle as my question. And just now I was reading about new 
> style classes, and it also seems like a bit of extra typing to have to 
> subclass object, but I guess that isn't something that can be implied 
> right now either.

"self" is conceptually necessary. Notice the similarities between 
doittoit() and It.doittoit():


py> def doittoit(it):
...   print it.whatzit
...
py> class It:
...   whatzit = 42
...   def doittoit(self):
...     print self.whatzit
...
py> anit = It()
py> doittoit(anit)
42
py> It.doittoit(anit)
42
py> anit.doittoit()
42


If you get this example, I'm pretty sure you will understand "self" and 
its necessity.



More information about the Python-list mailing list