[Tutor] why "self" in methods?

Gonçalo Rodrigues op73418 at mail.telepac.pt
Mon Apr 5 11:26:05 EDT 2004


Em Mon, 05 Apr 2004 07:13:08 -0800, Chris Lott <chris at chrislott.org>
atirou este peixe aos pinguins:

>Alan Gauld wrote:
>
> >>>>>class SomeClass(object):
> >>
> >>...     def sayHello(self):
> >>...         print "hi, I'm SomeClass"
> >>...
> >
> >
> > But sayHello is not unbound in the sense mentioned in the OP
> > (which actually may not be the right term!). What I was really
> > asking was what use (if any) do methods without a self parameter have?
>
>The OP (me) is completely clueless at the moment, but I was asking about 
>creating a method such as def noSelf() in your code below:
>
> >>>>class SomeClass(object):
> >
> > ...     def sayHello(self):
> > ...         print "hi, I'm SomeClass"
> > ...     def noSelf():
> > ...         print "I'm selfless"
>
>My original question was why, if it lacked a parameter, it didn't just 
>automatically take the parameter self...  that they can be created but 
>not used doesn't seem very Pythonic :)

That's a problem of the programmer, not of the language right?

Also, about the self controversy, think about nested definitions of
classes. You get into trouble with the implicit self thingy.

With my best regards,
G. Rodrigues



More information about the Tutor mailing list