Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82242

Re: When do default parameters get their values set?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <random832@fastmail.us>
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; 'parameters': 0.04; 'arguments': 0.09; 'booth': 0.09; 'executed': 0.09; 'received:internal': 0.09; 'subject:set': 0.09; 'def': 0.12; '(lambda': 0.16; 'block.': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'parameter.': 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; '>>>': 0.22; 'previously': 0.22; 'compiled': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'dec': 0.30; 'statement': 0.30; 'code': 0.31; 'once,': 0.31; 'received:66': 0.35; 'created': 0.35; 'false': 0.36; 'subject:?': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'from:no real name:2**0': 0.61; 'header:Message-Id:1': 0.63; 'more': 0.64; 'default': 0.69; 'subject:get': 0.81; '2014,': 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:in-reply-to:references :subject:date; s=mesmtp; bh=ynt8BoDMzNR0L6f30rbT95SCf8M=; b=spGs l5zaEj9ElDYIDLtDRWqQe00lJVV9uLrTFLhQ7D59igsS7VcXibpTx0hvL1tQatlJ e3eqPtrV/K8fBEKoM7QD0dtT7xn1LsXF9fqdTejZYDZEGYcpUzLeNL//AitAuweH VL4hH6r4XMzoZWyecm8lwhtR2F9ITkuM+TMlrrg=
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:in-reply-to :references:subject:date; s=smtpout; bh=ynt8BoDMzNR0L6f30rbT95SC f8M=; b=P+uNCsCBZqe1ktaV1LlYI9b+kxTyBg5YAQzgmltbH7ZxDwOxkVxkzEYC JRJ+W6IlS4FjFSkWL1ViuPGKe6GuQPriMRK83ZptNWtZQOT/QARYvYHLXNDDBR7c FoFeoQoZTEQG7c7HXBgjh3d7ZCWDqo0n0UU5WBDtNRqjjg9eJ8s=
X-Sasl-Enc Tcxnwm49Gvqm7ZlAotiWYx+Uy31s0WFHEOox5m1JCcgS 1418166473
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-0d23237d
In-Reply-To <XnsA3FED89759430duncanbooth@127.0.0.1>
References <54866F2E.1765.complang@piz.noip.com> <54866F2E.1768.complang@piz.noip.com> <XnsA3FED89759430duncanbooth@127.0.0.1>
Subject Re: When do default parameters get their values set?
Date Tue, 09 Dec 2014 18:07:53 -0500
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16782.1418166477.18130.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418166477 news.xs4all.nl 2952 [2001:888:2000:d::a6]:57772
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4222
X-Received-Body-CRC 2011201624
Xref csiph.com comp.lang.python:82242

Show key headers only | View raw


On Tue, Dec 9, 2014, at 16:18, Duncan Booth wrote:
> The default parameters are actually evaluated when the 'def' statement is 
> executed and the function object is created from the default arguments
> and 
> the previously compiled code block.

Which means that if you execute the def statement [or lambda] more than
once, you will get more than one instance of the default parameter.

>>> def f(): return (lambda x={}: x)
...
>>> f()() is f()()
False
>>> g = f()
>>> g() is g()
True

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

When do default parameters get their values set? "bSneddon" <bsneddon@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
  Re: When do default parameters get their values set? "Chris Angelico" <chris.angelico@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
  Re: When do default parameters get their values set? "Dave Angel" <dave.angel@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
    Re: When do default parameters get their values set? Duncan Booth <duncan.booth@invalid.invalid> - 2014-12-09 21:18 +0000
      Re: When do default parameters get their values set? random832@fastmail.us - 2014-12-09 18:07 -0500
        Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-09 18:44 -0800
          Re: When do default parameters get their values set? random832@fastmail.us - 2014-12-10 13:38 -0500
            Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-10 18:18 -0800
              Re: When do default parameters get their values set? Chris Angelico <rosuav@gmail.com> - 2014-12-11 13:24 +1100
                Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-10 18:50 -0800
              Re: When do default parameters get their values set? Steven D'Aprano <steve@pearwood.info> - 2014-12-11 03:15 +0000
                Re: When do default parameters get their values set? Rustom Mody <rustompmody@gmail.com> - 2014-12-10 19:26 -0800
                Re: When do default parameters get their values set? Ben Finney <ben+python@benfinney.id.au> - 2014-12-11 14:49 +1100
                Re: When do default parameters get their values set? Chris Kaynor <ckaynor@zindagigames.com> - 2014-12-11 09:10 -0800
                Re: When do default parameters get their values set? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-12 09:51 +1100
              Re: When do default parameters get their values set? random832@fastmail.us - 2014-12-11 15:44 -0500
  Re: When do default parameters get their values set? "Tim Chase" <tim.chase@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500

csiph-web