Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!solaris.cc.vt.edu!news.vt.edu!newsfeed-00.mathworks.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Why do class methods always need 'self' as the first parameter? Date: Wed, 31 Aug 2011 14:54:25 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 22 Message-ID: References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> NNTP-Posting-Host: panix3.panix.com X-Trace: reader1.panix.com 1314802465 2254 166.84.1.3 (31 Aug 2011 14:54:25 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 31 Aug 2011 14:54:25 +0000 (UTC) User-Agent: nn/6.7.3 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12484 In <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> "T. Goodchild" writes: > So why is 'self' necessary on class methods? It seems to me that the > most common practice is that class methods *almost always* operate on > the instance that called them. It would make more sense to me if this > was assumed by default, and for "static" methods (methods that are > part of a class, but never associated with a specific instance) to be > labelled instead. > Just curious about the rationale behind this part of the language. How would a method access instance variables without 'self'? They probably could have made 'self' a magical attribute that just appears out of thin air instead of being passed as an argument, like 'this' in C++. But would that really provide any benefit? -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"