Why the 'self' argument?
mwilson at the-wire.com
Fri Sep 5 21:56:26 CEST 2003
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.
More information about the Python-list