Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Thu, 19 Nov 2015 08:42:00 -0700 Lines: 18 Message-ID: References: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de EGoywUsfEt5BGgLEYb1XLgGG67aJzMjmmvDOFOaHFO+w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'defaults': 0.05; 'assignment': 0.07; 'attributes': 0.07; 'only,': 0.07; 'variable,': 0.07; 'happen.': 0.09; 'semantics': 0.09; 'python': 0.10; 'def': 0.13; 'thu,': 0.15; 'binding.': 0.16; 'defaults,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; '2015': 0.20; 'permitted': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'once,': 0.29; 'option': 0.31; 'problem': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'late': 0.38; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'waiting': 0.60; 'default': 0.61; 'real': 0.62; 'relatively': 0.63; 'binding': 0.66; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Q7U1wboQbpIOqcWK+tw4ibLezR/iApAZjWqhEFme4H0=; b=GnQFgXcP3in+dTysW3WzIC4N/Aqbuzvh199aXLHNpAEIoDo7uUA3SX/VmcrB5tq3Xn fCsd03CqkMwFPWZAc/g/XGtcI202qWXHAEaHu/G2Nf/uCASxNwavigZcdd9pm2oWM0PN YAjuA2hw2Y+b3+cJUSoRU+odI0bWKtrneBvmiMm1pjasfQAKO5zCOM4Ef1DXbEuklDk5 w7pbxrX0qG0Ek+ymgFZtNdIpvgP2DKgaNLdehp/YcXmIpgWVEf3j3ZI6FQuS/KqKCrHg JcPxm6jKznk4HCd1eDz0akpavQ2Oeef+lPXOQ/uNfnl3sxKkW655JCt4MFx4kaV112Da 66eg== X-Received: by 10.107.164.154 with SMTP id d26mr8992780ioj.111.1447947759991; Thu, 19 Nov 2015 07:42:39 -0800 (PST) In-Reply-To: <564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99063 On Thu, Nov 19, 2015 at 5:45 AM, Steven D'Aprano wrote: > But if you want the default value to be evaluated exactly once, and once > only, there is no real alternative to early binding. You could use a global > variable, of course, but that is no solution -- that's a problem waiting to > happen. It doesn't have to be a global. In a Python with late binding defaults, this would work to get early binding: def f(x=f.default_x): ... f.default_x = something() Of course, assignment to function attributes is a relatively modern thing that is only permitted since Python 2.1, whereas function defaults have been around since at least 1.4, so this wouldn't have been an option when the semantics were being determined.