Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'clean.': 0.09; 'expectation': 0.09; 'received:internal': 0.09; 'semantic': 0.09; 'subject:set': 0.09; 'def': 0.12; 'be:': 0.16; 'executed.': 0.16; 'lambda': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'subject:default': 0.16; 'subject:parameters': 0.16; 'subject:their': 0.16; 'subject:values': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; 'example': 0.22; 'equivalent': 0.26; 'header:In- Reply-To:1': 0.27; 'dec': 0.30; 'this.': 0.32; 'received:66': 0.35; 'false': 0.36; 'subject:?': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'from:no real name:2**0': 0.61; 'header :Message-Id:1': 0.63; 'skip:n 10': 0.64; 'different': 0.65; 'subject:get': 0.81; '2014,': 0.84; 'imperative.': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:x-sasl-enc:from:to:mime-version :content-transfer-encoding:content-type:subject:date:in-reply-to :references; s=mesmtp; bh=0vb+rjnkV6TjVF1HT5vFg+hwjrk=; b=bXG5eI X0z6BLFvfE8c3t6b+a/uZecFFX9H5kFZlLMxf+bI66aoxCz3kBKd3gFAS1/FEQJP B/HLYKcm/MeYZfDEDEW08ZKvvhs6hNhjYRsfCwl9cB9GhekRgf3cR2sty12GSRJs C8nWRL8tzXmAZZ8L0KzQEIUoISgZHRQzNOw+A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:x-sasl-enc:from:to :mime-version:content-transfer-encoding:content-type:subject :date:in-reply-to:references; s=smtpout; bh=0vb+rjnkV6TjVF1HT5vF g+hwjrk=; b=h6ULTw5plA364WTOZhbIfPclgDEscsmPxgcVYeaCyF5PzxIW1DUd ssPEBnZ5Vb4gdRQe6ceLNDEfvJxidp9spgLXrV9zxMq1ac7jEMT+BT99QUltdCal S9ixcRIdHgfKI8q7Lv4WkcflS0vx/dsgCjYoYgTrI3DG2ekOCFI8HFo= X-Sasl-Enc: wkVLb4MJtE9sEUf1hgZv0yT9QjpfAUZlHZCAG9PMqofF 1418236730 From: random832@fastmail.us To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-c5cca857 Subject: Re: When do default parameters get their values set? Date: Wed, 10 Dec 2014 13:38:50 -0500 In-Reply-To: References: <54866F2E.1765.complang@piz.noip.com> <54866F2E.1768.complang@piz.noip.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418236733 news.xs4all.nl 2916 [2001:888:2000:d::a6]:60283 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 4308 X-Received-Body-CRC: 1478800802 Xref: csiph.com comp.lang.python:82305 On Tue, Dec 9, 2014, at 21:44, Rustom Mody wrote: > Nice example -- thanks. > Elaborates the why of this gotcha -- a def(inition) is imperative. > From a semantic pov very clean. > From an expectation pov always surprising. Of course, I used a lambda for this. The equivalent without would be: def f(): def g(x={}): return x return g Ultimately it's no different from when any non-immutable expression is executed. def f: return {'x': {}} f()['x'] is f()['x'] # False d = f() d['x'] is d['x'] # True