Why the 'self' argument?

John Roth newsgroups at jhrothjr.com
Fri Sep 5 22:48:48 CEST 2003

"Mel Wilson" <mwilson at the-wire.com> wrote in message
news:qpOW/ks/KnRV089yn at the-wire.com...
> In article <vlhidvcpq9a980 at news.supernews.com>,
> "John Roth" <newsgroups at jhrothjr.com> wrote:
> >"Grant Edwards" <grante at visi.com> wrote in message
> >news:3f58b1f6$0$155$a1866201 at newsreader.visi.com...
> >> In article <vlhba85atlte07 at news.supernews.com>, John Roth wrote:
> >> >
> >> > "Grant Edwards" <grante at visi.com> wrote in message
> >> > news:3f58a2bd$0$156$a1866201 at newsreader.visi.com...
> >>  2) It would mean that there's some sort of difference between
> >>     a function and a method.
> >
> >I don't understand your point. There is currently a difference
> >between a function and a method that could be eliminated by
> >making self a reserved word and removing it from the method
> >header. Or have you never tried to invoke a method from the
> >wrong context and gotten the "unbound method" error?
>    There's no difference in the sense that a method is
> simply a function whose first parameter refers to the class
> instance to be worked on.  No magic words, no "undeclared"
> parameters.  It means that in my demo code in limitcases.py
> (somewhere in the newsgroup lately) I can say
>     limitcases.Lowest.__str__ = lambda x: "-Infinity"
> to give the Lowest class a new method sans ennuis.

But why do it that way? Neither Java nor Ruby require
giving the instance a name. Hence my comment that requiring
it is more complex than not requiring it.

John Roth
>         Regards.        Mel.

More information about the Python-list mailing list