Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'parameter.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; 'def': 0.15; "subject:' ": 0.15; 'python\xe2\x80\x99s': 0.16; 'reedy': 0.16; 'simplicity.': 0.16; 'val': 0.16; 'syntax': 0.16; 'wrote:': 0.16; 'level,': 0.18; 'jan': 0.19; 'seems': 0.20; 'header:In-Reply-To:1': 0.22; 'mask': 0.23; "python's": 0.24; 'function': 0.27; '(this': 0.28; 'bugs': 0.28; 'subject:need': 0.28; 'class': 0.30; 'subject:?': 0.31; 'there': 0.33; 'to:addr :python-list': 0.33; 'header:User-Agent:1': 0.34; 'things': 0.34; 'header:X-Complaints-To:1': 0.35; 'class.': 0.37; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'double': 0.61; 'below': 0.62; 'special': 0.67; 'clearer': 0.84; 'gut': 0.84; 'self.value': 0.84; 'subject:always': 0.84; 'subject:class': 0.84; 'subject:self': 0.84; 'hence,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Why do class methods always need 'self' as the first parameter? Date: Wed, 31 Aug 2011 12:30:59 -0400 References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314808320 news.xs4all.nl 2434 [2001:888:2000:d::a6]:37039 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12496 On 8/31/2011 10:35 AM, T. Goodchild wrote: > But one of the things that bugs me is the requirement that all class > methods have 'self' as their first parameter. On a gut level, to me > this seems to be at odds with Python=E2=80=99s dedication to simplicity= =2E Actually, it is a consequence of Python's dedication to simplicity. A=20 method is simply a function that is an attribute of a class. (This is=20 even clearer in Py 3.) Hence, there is no special syntax for methods. Consider def double(obj): return 2*obj.value class C: def __init__(self, val): self.value =3D val c =3D C(3) C.double =3D double c.doub =3D double # not c.double as that would mask access to C.double in c.double() below print(double(c), C.double(c), c.double(), c.doub(c)) # 6 6 6 6 --=20 Terry Jan Reedy