Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'value,': 0.04; 'attribute': 0.07; 'function,': 0.07; 'none:': 0.07; 'global,': 0.09; 'relies': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'subject:was': 0.15; 'binding,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'implemented.': 0.16; 'subject:=': 0.16; 'subject:Early': 0.16; '\xa0def': 0.16; 'language': 0.17; 'wrote:': 0.18; 'arguments': 0.18; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; '\xa0if': 0.23; 'static': 0.24; 'creating': 0.25; 'sat,': 0.25; 'code': 0.25; '(in': 0.26; 'function': 0.27; 'variable': 0.28; 'message- id:@mail.gmail.com': 0.28; '24,': 0.29; 'object.': 0.30; 'usually': 0.31; 'touch.': 0.32; 'subject:]': 0.32; 'to:addr :python-list': 0.34; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'steven': 0.38; 'received:209.85': 0.38; 'should': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'body': 0.61; 'alternative.': 0.84; 'together,': 0.84; 'variable:': 0.84; 'here...': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=5FRZzqcio0GfipRBTYbOTuyw7DCAiB9G82qLx8AurZ0=; b=GoPVVITTWwftHVKc+Q15vB/fWOUsUgQM3cSgzaOjIaBqpr/7NCG4z70AimF6OyWzOq R4V7eX35CkOvRSk1/kmMWBiHs4JiNy37HaszpgirExBtS4uVVznf6NrIDvTqlvcYCQzU lb23nv0egxdJMiz8xAVdHCExZD0bqr1GuUZoM= MIME-Version: 1.0 In-Reply-To: <4ef4a30d$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <18f78d0d-1e70-4c7b-9033-1422e6edb6db@t13g2000yqg.googlegroups.com> <10c62dac-2750-4f08-8962-21952c1c0a0b@v31g2000prg.googlegroups.com> <5a7a7aab-a320-4429-a130-ffcfcf0ac174@v24g2000prn.googlegroups.com> <4EF440A9.7030101@stoneleaf.us> <9ljcutFemiU5@mid.individual.net> <9ljd41Fp3bU1@mid.individual.net> <4ef4a30d$0$29973$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 24 Dec 2011 02:55:41 +1100 Subject: Re: Early and late binding [was Re: what does 'a=b=c=[]' do] From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324655745 news.xs4all.nl 6877 [2001:888:2000:d::a6]:48501 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17808 On Sat, Dec 24, 2011 at 2:49 AM, Steven D'Aprano wrote: > To fake early binding when the language provides late binding, you still > use a sentinel value, but the initialization code creating the default > value is outside the body of the function, usually in a global variable: > > =A0 =A0_DEFAULT_Y =3D [] =A0# Private constant, don't touch. > > =A0 =A0def func(x, y=3DNone): > =A0 =A0 =A0 =A0if y is None: > =A0 =A0 =A0 =A0 =A0 =A0y =3D _DEFAULT_Y > =A0 =A0 =A0 =A0... > > This separates parts of the code that should be together, and relies on a > global, with all the disadvantages that implies. A static variable (in the C sense) would make this just as clean as the alternative. In Python, that could be implemented as an attribute of the function object. Oh looky here... that's how default arguments are implemented. :) Tim Toady. ChrisA