[Tutor] q about method(self)

Erik Price erikprice@mac.com
Sat, 31 Aug 2002 10:45:19 -0400


A class method generally takes "self" as its first argument.  I had 
been wondering for some time why this is, since it seems redundant if 
it's there for all class methods.  But I just realized -- you can call 
an object's method without using dot notation in Python, like this:

method(instance_reference, args)

rather than only like this:

instance_reference.method(args)

I didn't realize that until just now.  But what I'm wondering is, 
why/when would you want to use this form?  Is it just an aesthetic 
thing, or is it something that is required b/c of the way that Python 
handles user-defined classes and objects?  Or something else?

One other quickie question -- not that I would ever need to do this, 
but could a different identifier other than "self" ever be used?  (such 
as "this")  It -appears- that "self" is just a reference within a 
class, but perhaps there's magic going on that I don't know about.



Thanks,

Erik





--
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org